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!