Basic: Data from Loop in matrix, then XLSwrite
Afficher commentaires plus anciens
I calculate the coordinates of B with point A and alpha. In a loop I want to vary the coordinates x_A and y_A in a 0.1-grid, starting at S=(x_S, y_S) and ending at T. Each A and related B should be written in an excel-sheet like this - first writing some unchanged values, then all A and B values:
x_S
y_S
alpha_1
alpha_2
x_A_1_1 x_A_1_2 ... x_A_1_m ... x_A_2_1 ... x_A_n_1 ... x_A_n_m
y_A_1_1 y_A_1_2 ... y_A_1_m ...
x_B_1_1 x_B_1_2 ... x_B_1_m ...
y_B_1_1 y_B_1_2 ... y_B_1_m ...
Here my try for the loops
for i=x_S:0.1:x_T
x_A(i)=x_S +i;
for j = y_S:0.1:y_T
y_A(j)=y_S +j;
end
A = [x_A; y_A];
B = [x_B; y_B] %calculated by trigonometric functions, where put it, inside loop or after/before?
end
So i want to save ALL A in a Matrix AM and all B in BM, so
A = [a1 a2 a3 .. a(n x m)] %in a (n x m)x2 Matrix
B = [b1 b2 .. b(n x m)]
for Saving it in the same excel sheet I want something like that:
xlRange_xS = 'A1';
xlRange_yS = 'A2';
xlRange_alpha1 = 'A3';
xlRange_alpha2 = 'A4';
xlRange_A = 'A5';
xlRange_B = 'A7';
xlswrite(filename1, x_S, sheet, xlRange_xS)
xlswrite(filename1, y_S, sheet, xlRange_yS)
...
xlswrite(filename1, AM, sheet, xlRange_A)
xlswrite(filename1, BM, sheet, xlRange_B)
I know some codes are wrong but hope you understand what the code SHOULD do. I realized it is better to first save all values in an array and then usw xlswrite for that array and not the single values. But how do I save the loop values A in a matrix and how the values for B? Can I even save them into the same array (if I cannot use xlswrite more then once). And I need the step to be 0.1, but it always shows the error
Subscript indices must either be real positive integers or logicals.
After reading a lot of questions today I cannot think clearly anymore and mix everything up. Thank you!
Réponse acceptée
Plus de réponses (1)
NF
le 4 Juin 2019
0 votes
Hi,
I have a cell array with multiple matrices. when using xlswrite, only one matrix appears at the xls file.
What should I do?
attached is the code
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!