How do I ascribe a variable to a cell?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Christian Huber
am 14 Dez. 2018
Bearbeitet: madhan ravi
am 14 Dez. 2018
Hi,
First of all thanks for reading this and trying to help :)
I am struggling with "attaching" my script to functions written by (many) others.
For that I need to take data out of a text file. In the function (not mine) the data later gets accessed using the command: soilstructure(1).thickness
I have tried with a table and a cell array and attributed the name 'thickness' to the last column, but it wont accept it as index, at least not using the above command... The error message reads: Struct contents reference from a non-struct array object.
Here is what I have so far:
layer = readtable('soil.txt',...
'Delimiter',' ','ReadVariableNames',false);
soilstructure = table2cell(layer,...
'VariableNames',{'type' 'radius' 'G' 'nu' 'rho' 'damping' 'thickness'});
x = soilstructure(1).thickness %why can't it access the data???
The table looks as follows:
soilstructure =
4×7 cell array
'L' [0] [6.8322e+06] [0.4900] [1840] [0.0500] [ 15]
'L' [0] [6.9898e+06] [0.4900] [1840] [0.0500] [ 15]
'L' [0] [2.5479e+07] [0.4900] [1840] [0.0500] [ 85]
'H' [0] [3.3425e+07] [0.4900] [1840] [0.0500] [NaN]
Thank you so much for your help
Chris
2 Kommentare
Akzeptierte Antwort
madhan ravi
am 14 Dez. 2018
Bearbeitet: madhan ravi
am 14 Dez. 2018
x = soilstructure{:,7} % but I don’t see your point of converting it to a cell from table but anyhow..
But if you want it to be treated as the way it was this is how I would do it:
remove soilstructure and replace it with (the reason for your error was it was a cell and you were treating it as a struct) the below , treats the data as a table as it was imported as a table
layer.Properties.VariableNames={'type'.... rest the same
layer.thickness % this will access the thickness column
8 Kommentare
madhan ravi
am 14 Dez. 2018
Bearbeitet: madhan ravi
am 14 Dez. 2018
You're welcome Chris , I suggest you to contact the person who coded the script so that you know what he/she mean by this.
Weitere Antworten (1)
Mark Sherstan
am 14 Dez. 2018
Bearbeitet: Mark Sherstan
am 14 Dez. 2018
It is a cell array not a structure. Retrieve the information as follows:
x = soilstructure{1,7}
0 Kommentare
Siehe auch
Kategorien
Mehr zu Cell Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!