How to write my for loop data into an array

2 Ansichten (letzte 30 Tage)
Michael Scott
Michael Scott am 2 Jun. 2022
Beantwortet: Stephen23 am 2 Jun. 2022
Hello I have a for loop that is extracting data from a matrix and finding the minimums and maximums. I need it to write all the maxes in a array rathter than provide individual ans for each loop.
clear all
opts = detectImportOptions('testforscripts.csv');
filename = "testforscriptsfull.csv"; %reads file of all data points
T = readtable(filename,opts); %synthesizes the data and creates a table of variables
Two0 = standardizeMissing(T, 0); %takes all values of 0 and replaces them with NaN
%create an equally spaced vector of values using the more general form start:step:end.
ElmID1 = [99109176:3:99110484]; %this is the elm ID vector
ElmID2 = [99110592:3:99110837];
row = 308; % rows per group
grp = size(Two0,1)/row; %creates smaller matrixes of each data set
for k = 1:grp
idr = (1:row)+(k-1)*row; %breaks large data into 308 data sets WITH NaN
Finalmatrix=rmmissing(Two0(idr,:)); %Removes all values of NaN
Force=(Finalmatrix(:,2)); %Extract the second coloum (force) for each loop
Array=table2array(Force); %turn the table into an array so it can be indexed
Maxes = max(Array); %maxes of each coloumn
Mins = min(Array); %mins of each coloumn
for i=1:length(Maxes)
MaxMatrix(:,i)= Maxes(:,1) *This is the part I'm stuck on, method is not working*
MaxMatrix(:,i)=[MaxMatrix , Maxes(:,1) ] *This is the part I'm stuck on, method is not working*
end
end

Antworten (1)

Stephen23
Stephen23 am 2 Jun. 2022
Maxes = cell(1,grp);
for k = 1:grp
..
Maxes{k} = max(Array);
end
Maxes = vertcat(Maxes{:}); % optional

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by