How to save data in a vector for each loop indice?
2 views (last 30 days)
Show older comments
Tanya Sharma
on 24 Aug 2021
Commented: Tanya Sharma
on 31 Aug 2021
I am unable to save the data for each loop entry to a vector, as it gives the error that array indices must be integers. How do I save data in vec for each indice of 'ii'?
clear;
clc;
ii=1:0.1:1.5;
vec=zeros(length(ii),1);
for x = ii
sol = x+1;
vec(ii)=sol;
end
0 Comments
Accepted Answer
Turlough Hughes
on 24 Aug 2021
Edited: Turlough Hughes
on 24 Aug 2021
x = 1:0.1:1.5;
vec=zeros(size(x));
for ii = 1:numel(x)
sol = x(ii)+1;
vec(ii)=sol;
end
vec
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!