Hi, there is a (1x6) vector that i want to extract values from. I used strings to pick-up the subtitle and now the problem is that i have to extract every value under the subtitle (e.g Oxygen). How to i extract those values without hardcoding ?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
WILLBES BANDA
am 27 Mär. 2020
Kommentiert: WILLBES BANDA
am 27 Mär. 2020
InputData;
strmeasurements = Measurements;
'Oxygen';
strcmp(strmeasurements,'Oxygen')
for = 1:1:length(strmeasurements)
if strcmp(strmeasurements,'Oxygen') > 0
3 Kommentare
Akzeptierte Antwort
Rik
am 27 Mär. 2020
It would probably make a more sense to use the table data type instead of a string array that is parsed to separate variables.
a=["Oxygen" "CarbonDioxide" "Temperature" "Pressure" "SolarRadiation"
"19.126323" "2316.074" "20.22159" "100.55903" "5.5317028e-05"
"21.649558" "1675.8466" "19.700265" "97.258761" "4.7879645e-05"
"21.365389" "5137.8534" "17.95304" "100.52854" "2.3418843e-05"
"20.849494" "4038.5941" "20.266467" "67.042816" "6.0612875e-05"
"20.435402" "1735.1865" "22.257325" "74.053206" "4.8704271e-05"
"23.822268" "3127.1723" "21.121039" "75.086682" "1.9341138e-05"
"19.171776" "2664.9685" "18.31899" "68.216119" "7.7129851e-05"
"19.860289" "2044.0518" "17.646104" "88.961919" "4.3741877e-05"
"21.355073" "2823.8126" "18.492655" "72.283582" "6.6637808e-05"];
for col=1:size(a,2)
L=ismember(a(1,:),a(1,col));
data=str2double(a(2:end,L));
switch a(1,col)
case "Oxygen"
Oxygen=data;
case "CarbonDioxide"
CarbonDioxide=data;
case "Temperature"
Temperature=data;
case "Pressure"
Pressure=data;
case "SolarRadiation"
SolarRadiation=data;
otherwise
%deal with unexpected input here
error('data type not recognized')
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Language Fundamentals 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!