weird problem while copying a double value from an array into another.
이전 댓글 표시
Hi, I have an array like this:
magnitude=[1,1.25,1.5,1.75];
I want to copy the values in it into another matrix with this:
row=1;
inj_duration = 192;
inj_starts_at=[108,120,132,144];
for node=1:G.NodeCount
for startTime=1:4
inj_sc(row,:)=[node , magnitude(startTime) , inj_starts_at(startTime) , inj_duration];
row=row+1;
end
end
And the result became integer in the inj_sc's second column.
However, if I use something like this, no problem appears:
inj_sc=[randi(G.NodeCount,Ns,1), max_inj_conc*rand(Ns,1), randi(48,Ns,1)+inj_start_time, randi(inj_duration,Ns,1)];
The result becomes [int, double, int, int] and this is the what I want. But I can't use random numbers, I have an order for my project.
Also, If I do the following in the command line, still no problem:
inj_sc(1,2)=0.34
So, what is the problem with my nesting loops?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!