Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Sums elements of a row

6 visualizaciones (últimos 30 días)
Riccardo Busin
Riccardo Busin el 22 de Feb. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hello everyone!
I have the following problem (I bring an example):
I am in this initial situation:
Company worker1 worker2 worker3 worker4 worker5
AAAAA M F F F M
BBBBB F F M
CCCC M M F M
DDDDD F M
I would like to get the sum of M and F for each line and have this as the final result:
Company worker1 worker2 worker3 worker4 worker5 SumM SumF
AAAAA M F F F M 2 3
BBBBB F F M 1 2
CCCC M M F M 3 1
DDDDD F F 0 2
Finally, save it all in excel
I attach a piece of code that I wrote (I don't know if it is right or useful to achieve the required result)
clear all;
clc;
load('DBTot.mat');
%%
n=size(DBTot,1);
m=size(DBTot,2);
DBGender=DBTot(:,[1,(7:4:m)]); % selec only the gender
DBGender=table2cell(DBGender);
n1=size(DBGender,1);
m1=size(DBGender,1);
clear DBTot
strDBGender=string(DBGender);
Thank you all!
  3 comentarios
Riccardo Busin
Riccardo Busin el 22 de Feb. de 2020
Thank you for your help!
I changed the example (I noticed that the companies I am examining have a different number of workers). In this new case, does the code you wrote remain the same?
Thanks again!
Walter Roberson
Walter Roberson el 23 de Feb. de 2020
DBGender = DBTot{:,7:4:m};
Looks more plausible to me. It would be odd to have gender as the first column.
By the way, you should be improving the logic to count all the other genders as well as M and F.

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by