range of value with doing calculation
3 views (last 30 days)
Show older comments
I just started using matlab two days before, I have a simple question regarding the calculation while using range of value with a constant. I encountered issue while doing this calculation.
x=0:1:50;
i=0.5;
y=abs(x-i);
as I know the values saved in matlab are all in the form of matrices, and the x is varied from [0,1,2,3,4,...,50] and it is a 1X51 matrix, and i is a 1x1 matrix, while I found that under the work space the y is also 1X1 matrix. Therefore, this is the reason why when I tried to plot the graph x-y, it appears only a dot, because the y is only 1 element inside.
Could anyone please show me the correct way to plot the graph and make sure the y is also a 1x51 matrix?
2 Comments
Walter Roberson
on 16 Apr 2020
Edited: Walter Roberson
on 16 Apr 2020
>> x=0:1:50;
i=0.5;
y=abs(x-i);
>> size(y)
ans =
1 51
y is a vector the same size as x.
The exception would be if there was some third-party abs.m on your path that was interfering with the Mathworks abs() function. To check that, see what shows up for
which abs(1)
You should see something along the lines of
toolbox/matlab/elfun/@double/abs %double method
if you see a .m file listed instead that that file is causing you problems.
Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots 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!