How can I run two loops at a time?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
for i = 1:length(Reff)
for j = 1:length(EC)
ILP= getsignal([num2str(EC(j)),'\','1100','\',num2str(Reff(i)),'um\out_resultsG_I0.dat']);
QLP= getsignal([num2str(EC(j)),'\','1100','\',num2str(Reff(i)),'um\out_resultsG_Q0.dat']);
I1(:,j)= smooth(sum(ILP,2));
Q1(:,j)= smooth(sum(QLP,2));
......
I want to include both the i,j indices in the I1 and Q1 syntaxes so that they run for both of the loops. By writing
ILP(i,j)= getsignal([num2str(EC(j)),'\','1100','\',num2str(Reff(i)),'um\out_resultsG_I0.dat']);
QLP(i,j)= getsignal([num2str(EC(j)),'\','1100','\',num2str(Reff(i)),'um\out_resultsG_Q0.dat']);
I1(i,j)= smooth(sum(ILP,2));
Q1(i,j)= smooth(sum(QLP,2));
I have the following error:
How can I solve it?
0 comentarios
Respuestas (2)
Jan
el 6 de Sept. de 2021
The error message means, that I1(i,j) is a scalar, but smooth(sum(ILP,2)) is not. You cannot assign an array to a scalar.
Maybe you want I1 to be a cell array? Then:
I1 = cell(length(Reff), length(IC));
...
I1{i,j} = smooth(sum(ILP,2));
0 comentarios
Star Strider
el 6 de Sept. de 2021
Apparently, that occurs when ‘ILP’ and ‘QLP’ become matrices rather than scalars, so when either ‘i’ or ‘j’ is greater than 1.
One option with in the loop would be to use cell arrays:
I1{i,j} = smooth(sum(ILP,2));
Q1{i,j} = smooth(sum(QLP,2));
and then sort the results out later.
With only the code provided, this is the only approach I can think of to solve it.
.
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!