Info

This question is closed. Reopen it to edit or answer.

I cant seem to get an output after using a for loop with my if statements. Im using CSVread along with the for loop to let matlab automatically read the data and generate my outputs.

1 view (last 30 days)
Im using CSVread along with the for loop to let matlab automatically read the data and generate my outputs. Here is some abstracts of my code;
m = csvread ('TestDataSheet.csv');
rows_to_examine = 36 : -1 + 14; %14 rows num_rows = length(rows_to_examine); result = cell(num_rows, 1);
for loop_m = 36 : 14 loop_m = rows_to_examine(row_idx);
val1 = m(loop_m,1); val2 = m(loop_m,2); val3 = m(loop_m,3); val4 = m(loop_m,4); val5 = m(loop_m,5); val6 = m (loop_m,6); val7 = m (loop_m,7); val8 = m (loop_m,8); val9 = m (loop_m,9); val10 = m (loop_m,10); val11 = m (loop_m,11); val12 = m (loop_m,12); val13 = m (loop_m,13);
if val3 <= 3 && val13 <= 3 && val10 <= 1.6 % top of tree, down far left hand side to far left value result{row_idx} = 'F(86.69/4.0)';
elseif val3 <= 3 && val13 <= 3 && val10 > 1.6 && val8 <= 161 result{row_idx} = 'T(5.0/1.0)';
elseif val3 <= 3 && val13 <= 3 && val10 > 1.6 && val8 > 161 result{row_idx} = 'F(4.0)';
end ...........that was the first if statement below is the end of my last if statement
else result = ('unconfirmed'); end end
fprintf('The Result Of The Test Is %s\n', result{:});
  1 Comment
Daniel kiracofe
Daniel kiracofe on 2 Nov 2016
It would help if you could post the TestDataSheet.csv file, along with the output that you got, and the output that you had expected to get (i.e. what did you get and why do you think it is wrong). Without more information about what you are trying to do, I cannot help.
However, this block of code really sticks out to:
val1 = m(loop_m,1); val2 = m(loop_m,2); val3 = m(loop_m,3); val4 = m(loop_m,4); val5 = m(loop_m,5); val6 = m (loop_m,6); val7 = m (loop_m,7); val8 = m (loop_m,8); val9 = m (loop_m,9); val10 = m (loop_m,10); val11 = m (loop_m,11); val12 = m (loop_m,12); val13 = m (loop_m,13);
That's really ugly. Instead of 13 separate variables, why not just one vector:
val = m( loop_m, 1:13)
then later instead of "if val3 <= 3" you can just do "if val(3) <= 3", etc. Must cleaner and easier to maintain.

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!