scatter a vector Matlab - matlab

to plot a vector I am using something like:
plot(1:length(vector),vector)
Could scatter be used? How?

If you're asking how to plot only points, without lines connecting them, just specify the marker and line style in the call to PLOT:
plot(1:length(vector),vector,'o'); % Use a circle with no connecting line

Scatter can be used in a similar fashion to plot.
scatter(1:length(vector),vector)

plot(vector,'o') is a simpler way.

Related

Is there a possibility to draw several cylinders or tubes in a matlab figure

I have 3-D plot in matlab and it contain several lines. I want to draw cylinder or hollow tubes around those line. Is someone has experience of plotting several cylinder in 3-D plot?
Yes, there is a possibility. There is a possibility of everything in Matlab!
Lets Google and find: cylinder()!
Fantastic, Matlab has a function to generate cylinders!
And... That's it. Go plot them wherever you want.
Fun:
clear;clc;
cmap = hsv(10);
for ii=1:10
hold on
[X,Y,Z]=cylinder(rand(1,1)*0.4);
h=surf(X+(rand(1,1)-10)*2,Y+(rand(1,1)-10)*2,Z*rand(1,1)*10,'FaceColor',cmap(ii,:));
end

Plotting a trapezium in MATLAB

How can I plot a figure in MATLAB such as a trapezium by giving only the vertices? I want the vertices connected by solid lines. I also want to calculate the area enclosed by the trapezium.
How can I do that?
There are many options for plotting.
plot, fill, patch would all be possibilities.
Use the function polyarea to give you the area specified by a set of vertices.
use fill(x,y,colour)
fill([1,2,3,4],[6,3,4,9],"red")
or plot(x,y) with the first elements repeated at the end:
plot([1,2,3,4,1],[6,3,4,9,6])
Edit: for the area
polyarea([1,2,3,4],[6,3,4,9])

Is it possible to plot two errorbars on one figure?

I need to plot two data vectors with errorbars on one figure. errorbar() function does it, but only for one data set. Is there a way to plot second graph on the same figure?
Been an idiot, forgive me. I just needed to pass in a two-dimensional matrices instead of vectors.

How to make a log plot in matlab

Is it possible to make a plot in matlab that does not actually take the logs of the values? I'm plotting wide ranges of values and when I try to make a log plot of them, those below 1 become negative. I would just like it to plot the values on a log scale without taking their logs.
Alternatively, set(gca,'XScale','log') if you have your plot already.
Yes, it is possible. Use the loglog command.
The example from the Mathworks website:
x = logspace(-1,2); % generate a sequence of points equally spaced logarithmically
loglog(x,exp(x),'-s')
grid on
If you do not want both axes to be log scale, use semilogx or semilogy.
So, you want to plot liner data on logarithmic axes? You can exponentiate you values before using the log plot. This way the point p=(10,3) will plot at the x=10 position.

Plotting images over a graph in Matlab

Does anyone know how can one plot() a regular 2D plot in Matlab,
and draw little images over that plot?
Thanks for any tips.
Hmmm, my bad, it's all there in the basic Matlab commands:
You do your plot(),
call 'hold on',
and then call 'image(x,y,img)' to plot that image on top of the existing plot.
:)