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!