I would like to associate to every name on the left an array with all the numbers on the right column associated to that name. Idk if this would be the best way of dividing the data according to the names, if you have other ideas I'm also open to new solutions
"NovanaModelTUDEAA" 19907
"NovanaModelB8" 0
"DK2013Hulbyrenden" 2456.9
"NovanaModelB53" 2000
"DKQNPAa62110222" 1349.5
"NovanaModelLINDESAADK1" 97
"DK20134780780" 0
"NovanaModelB18" 1469.5
"NovanaModelB28" 7581
"NovanaModelB18" 979.67
"DK2013Svenstruprenden" 2282
"NovanaModelB18" 1469.5
"NovanaModelB28" 2940
"NovanaModelTRYGGEVAELDEAA" 12481
"NovanaModelSKVL9" 617
"NOVANAMODELLERKENFELDAA" 29066
"NOVANAMODELVOLDBAEK" 4225
"NOVANAMODELLYNGBYGAARDSAA" 16316
"NOVANAMODELMODEBROBAEK" 4100
"DK20132255838" 0
"DK20132255838" 489.83
"NovanaModelVAEREBROAA" 17752
"DK20132255838" 0
"NovanaModelBjoerupBaek" 1437.9
"NovanaModelFribroedreAA" 13249
"NovanaModelFribroedreAA" 13249

댓글 수: 2

Matt J
Matt J 2021년 7월 27일
You have duplicate instances of names on the left with different values on the right. How would you wish to resolve that?
Chiara Scarpellini
Chiara Scarpellini 2021년 7월 27일
I would like to obtain something like this

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 27일

0 개 추천

findgroups(), and use the group numbers to splitapply() where the work function is @(x){x} . The results should be a cell array.
Now take the second output from the findgroups, the IDs output, which should be a cell array
struct('name', IDs, 'Qvolume', results_of_splitapply)
In the case where the values are cell array, then struct will create a struct array.

댓글 수: 6

Chiara Scarpellini
Chiara Scarpellini 2021년 7월 28일
편집: Chiara Scarpellini 2021년 7월 28일
T=table(string,ID_number)
save ('T.mat')
G=findgroups(T.string)
C=splitapply(@(x){x},T.ID_number,G)
R=struct('name',T.string,'Code',C)
Is working, but I didn't get what should I use as IDs instead of T.string
T=table(string,ID_number);
[G, IDs] = findgroups(T.string);
C = splitapply(@(x){x},T.ID_number,G);
R = struct('name', IDs, 'Code', C);
Chiara Scarpellini
Chiara Scarpellini 2021년 7월 28일
I obtain the same, for every cello of the name vector I have all the names of the measurements points instead of having just the one relative to the measures
T=table(string,ID_number);
[G, IDs] = findgroups(T.string);
C = splitapply(@(x){x},T.ID_number,G);
R = struct('name', cellstr(IDs), 'Code', C);
Chiara Scarpellini
Chiara Scarpellini 2021년 7월 29일
Perfect! Do you have an idea on how to sort C?
Walter Roberson
Walter Roberson 2021년 7월 29일
C has entries of different lengths; it is not clear what it means to sort it? If you mean you want each one to be sorted within itself then change to @(x){sort(x)}

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by