Displaying non existant array elements
Show older comments
Why am I getting repeating numbers for the array x as an output for the following piece of script?
x=1:0.5:5;
for i=1:length(x);
y(i)=x(i)^2;
end
fprintf(' x y\n')
Results=[x;y];
fprintf('%10.0f %38.16f\n', Results);
1 Comment
Stephen23
on 8 Mar 2025
“Why am I getting repeating numbers for the array x as an output for the following piece of script?”
You are not getting the same values repeating in x. You just confused how values are displayed with the values stored in memory. Try printing the values of x with e.g. two decimal places. Then tell us what you see.
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!