I have a matrix with 1000 real numbers within range -3 to 3. I have to plot the numbers on a graph so as to get a continuous curve combining all the points. The matrix name is Points and it is 1000 by 1 matrix.
try
plot(Points(:)); % plot the points
ylim([-3 3]); % set the y limits
Related
As far as I know, I can set number of contour lines, but they will be distributed evenly from min value to max value(for example, from 0.4 to 2.3). How can I set range for contour lines from 0.54 to 1.7 with step 0.04?
I use that function like that contour(x,y,po,20,'LineColor',[0 0 0]);
Specify the actual levels at which you want to draw the contours as the fourth input argument rather than the number of contours.
contour(x, y, po, 0.54:0.04:1.7, 'LineColor', [0 0 0])
contour(X,Y,Z,v) draws a contour plot of matrix Z with contour lines at the data values specified in the monotonically increasing vector v
I am importing data from three files and parsing it to obtain time and voltage values from each file. These values need to be plotted against each other on the same plot.
The data is held in a total of six matrices, one for time and one for voltage for each of the three data sets.
Matrix dimensions: matlab data sets: 1000x1, ltspice: 465x1, oscope: 2500x1.
Matlab finds an error in the use of the plot function:
plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');
Is this an issue because the matrix dimension vary between independent and dependent sets?
Full code for script:
clear;
clc;
%% Import
%Read in files
matlab_t=dlmread('ENGR_222_Project_1_data.csv',',',[16 0 1015 0]);
matlab_v=dlmread('ENGR_222_Project_1_data.csv',',',[16 1 1015 1]);
ltspice_t=xlsread('ltspicedata_excel.xlsx','A1:A465');
ltspice_v=xlsread('ltspicedata_excel.xlsx','B1:B465');
oscope_t=xlsread('oscope_data.xlsx','D1:D2500');
oscope_v=xlsread('oscope_data.xlsx','E1:E2500');
%% Plot
plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');
To plot multiple matrices on the same plot, each matrix must have the same dimensions. In the case where we have two 465 X 1 matrices, two 1000 X 1 matrices, and two 2500 X 1 matrices, all matrices must have the dimension 2500 X 1.
To increase the dimensions of the of the smaller matrices, redefine the matrix to that size and set the empty cells equal to zero.
This is accomplished in the following code:
matlab_t(2500,1)=0;
matlab_v(2500,1)=0;
ltspice_t(2500,1)=0;
ltspice_v(2500,1)=0;
Complete code using fix:
clear;
clc;
%% Import
%Read in files
matlab_t=dlmread('ENGR_222_Project_1_data.csv',',',[16 0 1015 0]);
matlab_v=dlmread('ENGR_222_Project_1_data.csv',',',[16 1 1015 1]);
ltspice_t=xlsread('ltspicedata_excel.xlsx','A1:A465');
ltspice_v=xlsread('ltspicedata_excel.xlsx','B1:B465');
oscope_t=xlsread('oscope_data.xlsx','D1:D2500');
oscope_v=xlsread('oscope_data.xlsx','E1:E2500');
% Redefine matrices to equal size
matlab_t(2500,1)=0;
matlab_v(2500,1)=0;
ltspice_t(2500,1)=0;
ltspice_v(2500,1)=0;
%% Plot
plot(matlab_t,matlab_v,'k',ltspice_t,ltspice_v,'j',oscope_t,oscope_v,'g');
I've been given a 1x16 matrix of temperature and a 1 x 21 matrix of humidity.
On top of that I have a 21x16 matrix of 0's and 1's where 0's are uncomfortable temp-humidity combinations and 1's are comfortable.
Any ideas on how I can go about plotting this graph and then finding a best-fit line to predict whether any temp-humidity pair is acceptable?
I have the following matlab code for approximating a differential equation via the Euler-method:
% Eulermethod
a=0;
b=0.6;
Steps=6;
dt=(b-a)/Steps;
x=zeros(Steps+1,1);
x(1,1)=1;
y=zeros(Steps+1,1);
for i=1:Steps
x(i+1,1)=x(i,1)+dt*(x(i,1)*x(i,1)+1);
end
plot(x)
I want to be able to plot the solution plot for several different values of Steps in one plot and have the x-axis go from 0 to 0.6 instead of from for example 1 to 100 000 etc. Can this be done?
If you use the hold on command this will allow you achieve multiple plots on the same figure. Similarly, if you separate your data into x and y vectors, you can plot them against eachother by passing 2 vectors to plot instead of just one. For example
figure
hold on
for i=1:m
x = [];
y = [];
%% code to populate your vectors
plot(x,y)
end
You should now see all your plots simultanesously on the same figure. If you want x to be composed of n equally spaced elements between 0 and 0.6, you could use the linspace command:
x = linspace(0.0,0.6,n);
In order to distinguish your plots, you can pass an extra paramter to the function .For example
plot(x,y,'r+')
will plot the data as a series of red + symbols.
Plot can take more arguments: plot(x_axis,values, modifiers);
If x-axis is a vector of M elements, values can be a matrix of MxN elements, each of which are drawn with a separate color.
Scatter Plots in MatLab. I can create a scatter plot with x and y arrays being the same size as follows:
function RasterTest()
clear all % clear memory
clc; % clear command window
close all; % close any figure windows that are open
x=[1 2 3]; % x positions of the charges
y=[4 8 2]; % y positions of the charges
scatter(x,y,'filled')
axis square
end
However, what if I want every x to have multiple y values? I.e. the array sizes are different. I think this is actually called a raster plot but MatLab doesn't seem to have something to do this?
Any help would be great :).
plot allows diferent size vectors
plot(x,[sin(x);2*sin(x);3*sin(x)],'*')
When the array sizes are different, how can you map every y value to the according x value? It's ambigous.
When you generate your data, just make sure that you insert every pair of values into the x and y arrays:
x = [1 2 3 1 3];
y = [3 4 5 6 7];
In the above example you got multiple points for the x values 1 and 3.