How can I have a script that allows me to obtain a cell array (3600,1) of this type?
1
2
3
4
.
.
.
24
1
2
3
4
.
.
.
24

2 Kommentare

Matt J
Matt J am 13 Sep. 2020
It is peculiar that you would want it to be a cell array. A numeric vector would be much more efficient.
Angela Marino
Angela Marino am 13 Sep. 2020
I need a cell array because this column of numbers must be associated with a cell array column where there are words. My code is:
for j=1:length(pers_ML_allSim)
for k=1:num_cluster_p
if idx_pers(j,1)==k && nome_allSim(j,1)==1
sumocfg_group(j,1)={'scenario base'};
sumocfg_group(j,2)={k};
elseif idx_pers(j,1)==k && nome_allSim(j,1)==2
sumocfg_group(j,1)={'perturbazione veicoli'};
sumocfg_group(j,2)={k};
elseif idx_pers(j,1)==k && nome_allSim(j,1)==3
sumocfg_group(j,1)={'perturbazione strada'};
sumocfg_group(j,2)={k};
elseif idx_pers(j,1)==k && nome_allSim(j,1)==4
sumocfg_group(j,1)={'perturbazione pedoni'};
sumocfg_group(j,2)={k};
end
end
end

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Matt J
Matt J am 13 Sep. 2020
Bearbeitet: Matt J am 13 Sep. 2020

0 Stimmen

reshape( num2cell((1:24).'*ones(1,150)) ,[],1)

Weitere Antworten (1)

Matt J
Matt J am 13 Sep. 2020
Bearbeitet: Matt J am 13 Sep. 2020

0 Stimmen

It might be beter to have a struct,
strArray=["scenario base","perturbazione veicoli","perturbazione strada","perturbazione pedoni"];
[UU,VV]=ndgrid(strArray,1:num_cluster_p);
idx=sub2ind(size(UU),idx_pers(:,1),nome_allSim(:,1));
sumocfg_group.column1=UU(idx);
sumocfg_group.column2=VV(idx);

1 Kommentar

Angela Marino
Angela Marino am 13 Sep. 2020
Error using sub2ind (line 55)
Out of range subscript.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by