3d plots in matlab based on a matrix [duplicate] - matlab

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Matlab 3D Matrix Plot
I have a matrix in matlab that I want to plot as a 3D figure.
Suppose the matrix looks like the following:
A=[4 7 8; 2 3 9 ]
This actually means the following data points in x,y,z plane
(1,1,4) (1,2,7) (1,3,8) (2,1,2) (2,2,3) (2,3,9)
I want to plot these values on a 3D graph.
How can I do that?

The function to use is surf(A)
This will plot your points from x = 1:2 and y = 1:3

Related

Save plot to a matrix in Octave/MatLab [duplicate]

This question already has answers here:
Save a plot in Matlab as a matrix [duplicate]
(2 answers)
Closed 6 years ago.
I wish to save a plot created in octave in a matrix
x=[0:10];
y=[0:10];
figure(1);
plot(x,y);
How can I save this plot into a matrix (or a 3D array, assuming it is RGB). To explain in a different way. Lets say there exist an image "img.jpg" in the working directory. Than i can open it as a matrix
A=imread("img.jpg");
How can one accomplish the same, having the plot saved in the matrix A?
Did you mean loading an image stored as a matrix into a variable? If so, You can use
A = load('img.mat')

How to assign vector elements to get a square wave? [duplicate]

This question already has answers here:
How to have square wave in Matlab symbolic equation
(3 answers)
Closed 6 years ago.
I have a vector T that is defined as
T=zeros(1,4)
I want to define T such that T(1) and T(2) are equal to 1 and T(3) and T(4) are equal to 0. So that when I plot T it looks like a square wave.
I have tried
for i=1:2:size(T,2)
T(i:i+1)=1
end
figure; plot(T);
But this does not give the desired result. It turns out to be [1,0,1,0].
What is the right way to do this assignment?
To differentiate from questions about plotting square waves:
I wanted to find out how exactly to create the loop that would plot to look like a square wave, without explicitly defining frequency or using the symbolic equation. I would then use this information to modify another script that would do the same thing but a larger vector T where the "period" is not the same. Sometimes it is 11s, sometimes 9s and so on.
The period is 4, not 2:
for i=1:4:size(T,2)
T(i:i+1)=1
end
figure; plot(T);
If you have access to the signal processing toolbox, an alternative is using the square function:
T = (1+square(0:pi/2:3*pi/2))/2 %// 1 1 0 0

How to plot from adjacency matrix? [duplicate]

This question already has an answer here:
Draw network or graph from matrix in matlab
(1 answer)
Closed 7 years ago.
I have an adjacency matrix and corresponding labels. I need to plot a network with weighted edges and different colors based on labels. I found there is gplot function in matlab, but it is not created weighted edges. Does anyone know any toolbox or function or something I can use?
There is a tool called wgPlot by Mike Wu that will allow you to plot weighted adjacency graphs easily.
wgPlot by MikeWu
Note that the edges are not labeled textually, but by a color scale.

(Matlab) How can I make 3D plot from 2D experimatal data? [duplicate]

This question already has an answer here:
3d plot with given 2d data
(1 answer)
Closed 8 years ago.
There are 2D experimental data.
z=load('data.txt');
x=z(:,1);
y=z(:,2);
plot(x,y)][1]
I want to make it to 3D as the link did.
Here is a link. 3d plot with given 2d data
The question and answer is a bit misleading, since the question is actually not regarding data but the bell function (or triangular function). They are symmetric and have corresponding 2D versions (see: http://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function).
y=exp(-x.^2/2); %1D
z=exp(-(X.^2+Y.^2)/2); %2D
In general, however, this is not the case. Your data, for instance, is not 2D:
z=load('data.txt');
x=z(:,1);
y=z(:,2);
x is 1D and y is your dependent variable. If x and y were independent you would have a third variable (e.g. z):
x=[0,1,2];
y=[0,1,2];
z=[1,2,3;
2,2,2;
3,2,1];
The entries in z would then be z(x,y) (e.g. z(3,3)=1).
To sum up the confusion:
When you plot a 1D function it is plotted in 2D (x,y),
and when you plot a 2D function it is plotted in 3D (x,y,z), (x,y,colors) or (x,y,z and colors) (the latter is what is used in the mentioned question).

Arranging Multiple Images in MatLab [duplicate]

This question already has an answer here:
How does subplot work and what is the difference between subplot(121) and subplot(1,2,1) in MATLAB?
(1 answer)
Closed 8 years ago.
I'm using MatLab for Image processing. I want to show images and histograms in 4 rows and and 2 columns but I fail to plot them
my code is below
% Show the images
subplot(1,2,1);imshow(I);
subplot(2,2,1);imshow(G);
subplot(3,2,1);imshow(B);
subplot(4,2,1);imshow(L);
% Plot Histograms
subplot(1,2,2);plot(h);
subplot(2,2,2);plot(hG);
subplot(3,2,2);plot(hB);
subplot(4,2,2);plot(hL);
according to the MatLab Documentation subplot(totalNoOfRows,totalNoOfCols,Position);
Positions are
1 2
3 4
5 6
7 8
error free code is here
% Show the images
subplot(4,2,1);imshow(I);
subplot(4,2,3);imshow(G);
subplot(4,2,5);imshow(B);
subplot(4,2,7);imshow(L);
% Plot Histograms
subplot(4,2,2);plot(h);
subplot(4,2,4);plot(hG);
subplot(4,2,6);plot(hB);
subplot(4,2,8);plot(hL);