Building a matrix inside a for loop

1 Ansicht (letzte 30 Tage)
Murstoe
Murstoe am 15 Mai 2020
Kommentiert: Rena Berman am 1 Jun. 2020
Hi guys, can anyone help me with this please. Thanks.
So i have this Excel file. I filtered a column and then did some operations on the filtered data .
in the end, I wanna create a new matix, A, with the following characteristics. The matrix should have dimension: partID rows* 5 columns. First colum should contain the partID number (from 3 to 15), second column should contain the value of M associated with the partID, third column S, fourth m and fifth s.
how do i build A inside the cycle?
  6 Kommentare
Murstoe
Murstoe am 23 Mai 2020
Guys I’m so sorry I don’t know what happened to it. I will sure fix it. I apologise again
Rena Berman
Rena Berman am 1 Jun. 2020
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 16 Mai 2020
Bearbeitet: Turlough Hughes am 16 Mai 2020
You could do it as follows:
xlsData = xlsread('PartS_all.xlsx');
partID = xlsData(:,4);
uPartID = unique(partID).'; % Unique part IDs
% Preallocate space
c = 0;
A = zeros(numel(uPartID),5);
for currPartID = uPartID
c = c+1;
part = xlsData(xlsData(:,4) == currPartID,:); %edit
A(c,:) = [currPartID mean(part(:,8)) std(part(:,8)) mean(part(:,11)) std(part(:,11))];
end
  2 Kommentare
Murstoe
Murstoe am 16 Mai 2020
I get the following error:
Index in position 2 exceeds array bounds (must not exceed 1).
Error in Untitled (line 25)
A(c,:) = [currPartID mean(part(:,8)) std(part(:,8)) mean(part(:,11)) std(part(:,11))];
Turlough Hughes
Turlough Hughes am 16 Mai 2020
I made a mistake. It should work fine now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import from MATLAB 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