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

Turlough Hughes
Turlough Hughes 2020년 5월 15일
Can you share the file?
Murstoe
Murstoe 2020년 5월 15일
thanks you, Here is the file excel.
Turlough Hughes
Turlough Hughes 2020년 5월 23일
Murstoe, it's bad form to remove your question after being given an answer. Can you put it back?
Original question from Google Cache:
"Building a matrix inside a for loop"
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?
xlsData = xlsread('PartS_all.csv');
partID=xlsData(:,4);
for partID=3:15
tenpm=xlsData(xlsData(:,4)==partID,:);
part=sortrows(tenpm, 2); %Sort second column
M(partID)=mean(part(:,8));
S(partID)=std(part(:,8));
m(partID)=mean(part(:,11));
s(partID)=std(part(:,11));
A=
end
Murstoe
Murstoe 2020년 5월 23일
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 2020년 6월 1일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

 채택된 답변

Turlough Hughes
Turlough Hughes 2020년 5월 16일
편집: Turlough Hughes 2020년 5월 16일

0 개 추천

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

Murstoe
Murstoe 2020년 5월 16일
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 2020년 5월 16일
I made a mistake. It should work fine now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

질문:

2020년 5월 15일

댓글:

2020년 6월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by