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!