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

 采纳的回答

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 个评论

num2cell(DR, 1) splits by column, and num2cell(DR,2) splits by row.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by