using the data from struct
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohamed Ibrahim
am 14 Feb. 2020
Kommentiert: Fangjun Jiang
am 14 Feb. 2020
hello i have a small problem
i have a code and when i run it its solution appear as a struct
the problem is i want to take some data from this struct aىd use it as a input for another code but i can't when i enter the name of a field in structure for example CL matlab tells me Undefined function or variable 'CL'.
i want this structure outputs to appear in my workspace like that
any suggestions please :)
2 Kommentare
Stephen23
am 14 Feb. 2020
Bearbeitet: Stephen23
am 14 Feb. 2020
You should allocate the structure to a variable, e..g.:
S = function_that_returns_a_structure(...);
Then you can trivially refer to its fields, e.g.:
S.Re
S.CD
S.Ncrit
etc.
"i want this structure outputs to appear in my workspace like that"
Do not convert structure fields to variables, unless you want to force yourself into writing slow, complex, buggy code that is hard to debug.
Akzeptierte Antwort
Fangjun Jiang
am 14 Feb. 2020
If you can't change the other program, Out=YourOtherProgram(), where "Out" is a data like "ans" in your picture,
then you can use Out.CL, Out.CD, etc.
There are functions like struct2array(), struct2cell() that you can use.
2 Kommentare
Fangjun Jiang
am 14 Feb. 2020
"ans" is the reserved variable name used by MATLAB. Use a different name.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!