How to make a loop inside a loop?

2 views (last 30 days)
MUHAMMAD FITRI
MUHAMMAD FITRI on 24 May 2022
I want to make a coding that for one set of data that consist 12502 datas, it will equal to 0. Then, for the next data it will equal to 4 with the increment of 4 as the code below. But the error came out says that dimension is not
for i = 0:10
filename1 = [folder_name, '\C14km spliced all disp0000', int2str(i), filenameExtension];
tmpData = dlmread(filename1); % Amplitude data
filename2 = ('distance.txt');
tmpData1 = dlmread(filename2); % Distance
E =[tmpData,tmpData1];
dlmwrite('newData.txt', E); % Amplitude with Distance
%save 'newData.mat',E;
OneMatrix = [TempMatrix;E];
TempMatrix = OneMatrix ;
for selaMasa = 1: length(TempMatrix)
tempSela = zeros(12502,1);
tempSela = tempSela + 4;
hold on
end
end

Answers (1)

Constantino Carlos Reyes-Aldasoro
Difficult to answer without more context, but I suspect that the error is not related to the loops but something else. There are other points that whilst not errors, will not work:
for selaMasa = 1: length(TempMatrix)
tempSela = zeros(12502,1);
tempSela = tempSela + 4;
hold on
end
In this case, every time you enter the loop, you initialise your variable tempSela to zeros, then add four. So, no matter how many times you iterate inside the loop, the answer will always be 4 for every value of tempSela. You could simply do the following:
tempSela = zeros(12502,1) + 4*length(TempMatrix);
In addition, hold on is used when you create a figure, plot something that you want to keep and then plot something else. In this case it is not necessary.
Hope this helps.

Products

Community Treasure Hunt

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

Start Hunting!

Translated by