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

 Respuesta aceptada

Rik
Rik el 25 de Mzo. de 2019

0 votos

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 comentario

Walter Roberson
Walter Roberson el 26 de Mzo. de 2019
num2cell(DR, 1) splits by column, and num2cell(DR,2) splits by row.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Mzo. de 2019

Comentada:

el 26 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by