multi cell array shifting when importing data
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have a cell array called "Variables" that contains also a cell for each variable I want to import in each iteration of my "Import Script". The files can contain doubles, and strings.
Each column corresponds to each variable that the file has (e.g. Sex, Height), and each row to a sample (e.g. Person1, Person2, etc.). The thing is that sometimes new variables comes (e.g. Sex, Height, Weight ) . Then, I need to fill the previous data with NaN-NaT or whatever values.
Example: (eof = 'end of file')
Sex Height
P1 m 2
P2 f 1.5
eof1-------------------- ->> MyOutput: Variables: 1x1 cell, Variables{1,1}: 1x2 cell array: {2×1 cell} {2×1 double}
Sex Height
P3 m 2
eof2-------------------- ->> MyOutput: Variables: 1x2 cell Variables{1,2}: 1x2 cell array: {1×1 cell} {1×1 double}
Sex Height Weight
P4 f 1.5 80
P5 m 2 75
eof3-------------------- ->> MyOutput: Variables: 1x3 cell Variables{1,3}: 1x3 cell array: {1×1 cell} {1×1 double} {1×1 double}
Height Weight
P6 1.5 90
eof4-------------------- ->> MyOutput: Variables: 1x4 cell Variables{1,4}: 1x2 cell array: {1×1 double} {1×1 double}
Then I would need a final matrix like this (I use concatenation to make this one):
Sex Height Weight
P1 m 2 NaN
P2 f 1.5 NaN
P3 m 2 NaN
P4 f 1.5 80
P5 m 2 75
P6 NaN 1.5 90
The problem seems to be simple but when working with the textscan function it becomes hard to handle automatically with no errors (my dataset is really big so I need to do it automatically).
This is a short example of my variables' worspace:
Hope I could explain my question properly,
Thank you very much
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Text Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!