How save the array?
5 次查看(过去 30 天)
显示 更早的评论
I have an array satring from 0.1 to 1 with 0.1 difference. I have to use it in foor loop. It is required that ra has to be in the below format.
for ra=0.1:0.1:1
%do something
end
howover, the value of ra is also have to be stored in a different array. Lets say the array is raz. How can I store the value of ra with each iteration in raz? I hope i have been able to explain the question
0 个评论
回答(1 个)
Andres Montes
2023-3-29
Hi, you can first store the raz and then use it in a for:
raz=(0.1:0.1:1)
for ra=raz(1):raz(end)
%Do something
end
In this way you'll have both, the for and the variable
1 个评论
Andres Montes
2023-3-29
Another thing you can do is declare the variable raz, and then use positions in the for instead of the actual numbers
raz=(0.1:0.1:1)
for i=1:length(raz)
ra=raz(i);
%Do something
end
In this way you can have your vector raz and utilize the value you need by calling a speific element of the vector
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!