How to simplify this If command?
古いコメントを表示
I have a string of 36 numbers that I am reading in from a file and each number means something specific. I am trying to write a for loop/if statement combo that reduces the amount of arguments I need within the if statement and then stores it into a struct that I'll later make into a table. I know that I am reading in the data fine and that my varible "s" is the correct string of numbers, but once I enter the for loop I skip over the if statement entirely and display "Inside For" 35 times with no other result. Is there a way to avoid having to state if i == 1 || i == 4....etc? So far my code is as follows:
s = textscan(sentence.data,'%d%d%d%d%f%f%f%d%f%f%f%d%f%f%f%d%f%f%f%d%f%f%f%d%f%f%f%d%f%f%f%d%f%f%f%d','Delimiter',',');
for i = [1:36]
disp('Inside For...'); %these display functions are to check my work
if i == [1:3:36]
disp('Inside IF...'); %never get this message
carnum = s(i);
speed = strcat('car ', carnum, ' speed');
struct(c).(speed) = s(i+1);
struct(c).carnum = carnum;
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!