Storing results from a nested for loop
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Dear all,
May you please find my attached file for my question regarding how to store the results from a nested for loop. I want the nested for loop storing the results as expected resulted in the attached file.
N = 2;
M = 8;
for i = 1:1:N
      for j = 1:1:M
          if swat_subbasin_id(j) == subbasin_id(i)
              ID = s_tillage_id(j);
          end
      end
     tillage_id(i) = ID;
  end
  AA = tillage_id';
  disp(AA);
Thank you so much for your help! Best regards, Dat
1 Commento
  Pavel Dey
    
 il 7 Giu 2016
				Not sure if I understood your question correctly. Are you stuck at storing the results in an excel sheet? To read from and write to an excel sheet you will have to use 'xlsread' and 'xlswrite' functions. Refer to the documentation below
Risposta accettata
  Iain
      
 il 7 Giu 2016
        Well theres two ways:
1. Write the results to file as they are generated. (xlswrite & xlsread would be your friends, and you just need to tell them where to write the latest value(s) as needed.) There are better options than xlswrite though.
2. Write the results to a 2-D variable, so, in your inner loop, you would have:
 tillage_id(i,j) = s_tillage_id(j)
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


