how to store and display values coming from the for loop to an array variable.

for ...
....
[m n]=min(MSE);
MSE(n);//how this value of each ittration is store in an array?? And How can I display It?
end

Antworten (1)

Aishwarya - if each iteration of your loop creates a variable (of some kind) that you want to store or save for further processing (or display) then you would initialize an array (or matrix) to store that data and update it on each iteration of your loop. For example, if you know how many iterations there are for your loop then
% 1. each iteration creates a scalar
numberOfIterations = 42;
scalarData = zeros(numberOfIterations, 1);
for k = 1:numberOfIterations
scalarData(k) = k^2 + k + 23; % or whatever, this is just an example
end
or
% 2. each iteration creates the same sized array
numberOfIterations = 42;
arrayOutputLength = 13;
matrixData = zeros(numberOfIterations, arrayOutputLength);
for k = 1:numberOfIterations
matrixData(k,:) = randi(1,arrayOutputLength);
end
or
% 3. each iteration creates the same sized matrix
numberOfIterations = 42;
matrixOutputNumberOfRows = 12;
matrixOutputNumberOfCols = 12;
matrixData = zeros(matrixOutputNumberOfRows, matrixOutputNumberOfCols, numberOfIterations);
for k = 1:numberOfIterations
matrixData(:,:, k) = rand(matrixOutputNumberOfRows,matrixOutputNumberOfCols);
end
or
% 4. each iteration creates a different sized matrix (use a cell array)
numberOfIterations = 42;
cellData = cell(numberOfIterations, 1);
for k = 1:numberOfIterations
cellArray{k} = rand(randi(42), randi(12));
end
or something similar to the above.
As for displaying your data it will depend upon what it is...but you may want to start with plot

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 27 Apr. 2019

Beantwortet:

am 27 Apr. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by