Matlab code to psudocode

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

 Risposta accettata

Rik
Rik il 25 Mar 2019
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 Commento

Walter Roberson
Walter Roberson il 26 Mar 2019
num2cell(DR, 1) splits by column, and num2cell(DR,2) splits by row.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by