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

Matt J
Matt J 2020년 9월 13일
It is peculiar that you would want it to be a cell array. A numeric vector would be much more efficient.
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2020년 9월 13일
편집: Matt J 2020년 9월 13일

0 개 추천

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

추가 답변 (1개)

Matt J
Matt J 2020년 9월 13일
편집: Matt J 2020년 9월 13일

0 개 추천

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

Angela Marino
Angela Marino 2020년 9월 13일
Error using sub2ind (line 55)
Out of range subscript.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Types에 대해 자세히 알아보기

태그

질문:

2020년 9월 13일

댓글:

2020년 9월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by