How can I run two loops at a time?

2 次查看(过去 30 天)
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?

回答(2 个)

Jan
Jan 2021-9-6
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));

Star Strider
Star Strider 2021-9-6
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.
.

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by