structure

R Turning a list into a matrix when the list contains objects of “different size”

徘徊边缘 提交于 2019-12-11 19:53:54
问题 I've seen a couple of questions about turning matrices into lists (not really clear why you would want that) but the reverse operation I've been unable to find. Basically, following # ind.dum = data frame with 29 observations and 2635 variables for (i in 1:ncol(ind.dum)) tmp[[i]]<-which(rollapply(ind.dum[,i],4,identical,c(1,0,0,0),by.column=T)) I got a list of 2635 objects, most of which contain 1 value, bust some up to 7. I'd need to convert this to a matrix with 2635 rows and as many

How to sort an array of structures according to values of one of its members, breaking ties on the basis of another member?

北战南征 提交于 2019-12-11 19:52:49
问题 Suppose there is a structure: struct x { int a,b,c; }; The array of structure contains arr[0]={4,2,5}, arr[1]={6,3,1}, arr[2]={4,1,8} then how can we sort this array in ascending order depending on value of member 'a',. tie will be broken according to value of member 'b'. So array after sorting should be : arr[2],then arr[0], then arr[1]. I have used qsort(arr,n,sizeof(struct x),compare); with compare function defined as int compare(const void* a, const void * b) { return (*(int*)a-*(int*)b);

Contact manager with c program by using structure

假装没事ソ 提交于 2019-12-11 18:44:31
问题 struct contact { char name[20],email[20]; int hpnum; }add; int option; int main (void) { system("cls"); printf("==========Welcome to Jeffery's Contact System Management==========\n"); printf("\t\t\tContact System Main Menu\n"); printf("[1] Create a New Contact\n"); printf("[2] Modified Existing Contact\n"); printf("[3] Delete Existing Contact\n"); printf("[4] Search Existing Contact\n"); printf("[5] Exit\n"); printf("Please enter one of your option.\n"); scanf("%d",option); switch(option) { /

Explain the result of sizeof operator for a union containing structures

不打扰是莪最后的温柔 提交于 2019-12-11 16:26:27
问题 #include<stdio.h> struct mystruct { char cc; float abc; }; union sample { int a; float b; char c; double d; struct mystruct s1; }; int main() { union sample u1; int k; u1.s1.abc=5.5; u1.s1.cc='a'; printf("\n%c %f\n",u1.s1.cc,u1.s1.abc); k=sizeof(union sample); printf("%d\n\n",k); return 0; } The size of operator is returning 8 I am still able to access the structure elements, more than one at a time and still the sizeof operator is returning the max size of primitive data types i assume. Why

Converting c structure with union to Delphi record

给你一囗甜甜゛ 提交于 2019-12-11 15:57:34
问题 I'm wondering if this c structure I've translated to Delphi is incorrect, and if incorrect, how it can be translated properly? Since the union is mid structure it seems it's not as simple to convert this properly. Any help would be much appreciated typedef struct FWPM_FILTER0_ { GUID filterKey; FWPM_DISPLAY_DATA0 displayData; UINT32 flags; GUID *providerKey; FWP_BYTE_BLOB providerData; GUID layerKey; GUID subLayerKey; FWP_VALUE0 weight; UINT32 numFilterConditions; FWPM_FILTER_CONDITION0

bytes were returned when we access the structure member and Segmentation fault occurs when printing structure variable address [duplicate]

纵然是瞬间 提交于 2019-12-11 15:53:23
问题 This question already has answers here : Crash or “segmentation fault” when data is copied/scanned/read to an uninitialized pointer (5 answers) Closed last year . I created one struct and assigned one pointer variable to that structure. When I tried to print the address of that variable it prints correctly. After assign value to one of the member of the structure using this pointer structure variable, when i tried to print the address of the pointer variable I got segmentation fault .

How to scan through several structures in MATLAB?

混江龙づ霸主 提交于 2019-12-11 15:11:32
问题 I have some structure arrays (like structure1, structure2, structure3,...) with similar field names. I want to scan through all the structures and return only those whose first field is 5 (Field1==5). I have this code so far, for k=1:3 s=sprintf('Structure%d',k) Structure=load(s) idx=cellfun(@(x) x==5, {Structure.Field1}) out=Structure(idx) v{k}={Structure.Field1} end but it gives me this error: Reference to non-existent field 'Field1'. Can someone please point out whats wrong here? Thanx 回答1

How should I name a header file designed for one structure

我是研究僧i 提交于 2019-12-11 14:29:43
问题 I have a structure called NDPlane , and I want to put it in its own file by following this answer. To avoid confusion as this just being an Objective-C interface for an NDPlane object, how should I name the file? ndplane.h , plane.h , or struct_NDPlane.h , etc... 来源: https://stackoverflow.com/questions/21343553/how-should-i-name-a-header-file-designed-for-one-structure

Does Aliasing/Alignment issues occur for an Array within a Structure?

守給你的承諾、 提交于 2019-12-11 14:09:28
问题 If we have an array within a struct: struct Names { uint8 fileId; uint8 name[50]; }; and then we try to assign a uint16 from the array to a uint16 variable like: uint16 someName = *((uint16 *)&NamesObj.name[21]); Will this violate aliasing rule/alignment rules and lead to undefined behaviour? 回答1: Yes, this violates C rules. The objects in name are uint8 (presumably some unsigned 8-bit integer type), and they are accessed through a pointer to uint16 (presumably some 16-bit integer type). The

How is 'let' implemented?

徘徊边缘 提交于 2019-12-11 13:53:21
问题 I pulled this example straight from this Apple page struct FixedLengthRange { var firstValue: Int let length: Int } and if you assign an instance of this structure to a constant, let rangeOfFourItems = FixedLengthRange(firstValue: 0, length: 4) it says we can't change its property values even if it is declared as 'var' This makes me wonder how let is implemented? I hope any assignments to it can be detected at compile time and show compile error. But in the above case, why does it apply to