Can anybody please tranlsate this Matlab code to Psudocode.
DR=DATARESOURCE
T= TIME
DS= DATASET
DR=[ 10 20 30 40 50; 29 32 43 57 60; 41 54 63 77 80 ; 21 33 45 99 76; 17 82 44 68 91];
for i=1:5
T{i} = (DR(:,i));
DS{i}=( DR(i,:));
sumDS{i}=sum(DS{i});
end

 채택된 답변

Rik
Rik 2019년 3월 25일

0 개 추천

I will do you one better: I will write comments with each line, which the writer of this code should have done. Then you can easily convert it to pseudocode.
DR=[ 10 20 30 40 50; 29 32 43 57 60; 41 54 63 77 80 ; 21 33 45 99 76; 17 82 44 68 91];
for i=1:5
T{i} = DR(:,i);%store a col of DR in the time array
DS{i}= DR(i,:);%store a row of DR in the DS array
sumDS{i}=sum(DS{i});%compute the sum of the row
end
This code can be optimized a lot, but without knowing the context of this code, it is tricky to give solid advice about which parts should definitely be changed. I supect something like this is a step in the right direction:
DR=[ 10 20 30 40 50; 29 32 43 57 60; 41 54 63 77 80 ; 21 33 45 99 76; 17 82 44 68 91];
T=mat2cell(DR,size(DR,1),ones(1,size(DR,2))); %split DR by column
DS=mat2cell(DR,ones(1,size(DR,1)),size(DR,2));%split DR by row
sumDS=num2cell(sum(DR,2));%compute row-sum
%or alternatively:
%sumDS=cellfun(@sum,DS,'UniformOutput',false);

댓글 수: 1

Walter Roberson
Walter Roberson 2019년 3월 26일
num2cell(DR, 1) splits by column, and num2cell(DR,2) splits by row.

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

추가 답변 (0개)

카테고리

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

질문:

2019년 3월 25일

댓글:

2019년 3월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by