Hi everyone,
I have a simple 1x3 table
T=[35 40 45]
Below is a sample syntax from class (not my code).
I'm trying to figure out how to use x and y1 based on the code below.
Also how I could use subplot if I have multiple rows and columns.
I appreciate all the help. Thanks.
x = linspace(-2*pi, 2*pi)
y1 = sin(x);
plot(x,y1)

5 commentaires

madhan ravi
madhan ravi le 23 Oct 2020
What you have is an array with 3 elements, you need to elaborate what you want to do with those three values?
Hi Ravi,
Thanks for the quick reply.
The 3 elements are temperatures in 3 different cities.
The first column is let's sayToronto, column 2 is Montreal and 3 is Vancouver.
I'm able to plot the data and get a line. But I'm trying to get a sin wave instead. I'm wondering if that's possible.
Hi Guys,
I took time to think about the problem then drew on paper to understand the problem better. I was able to figure it out.
My code below.
Temp_T = [25 35 35 30 30]; %Temperature Toronto
T = [2 3 4 5 6]; %Time between 2PM- 6PM
subplot(1,6,1)
x = T
y1 = Temp_T
plot(x,y1, 'LineStyle','--','color','g','Marker','o','MarkerSize',5)
xlabel('Time 2:00 PM - 6:00 PM')
ylabel('Toronto','Color','blue')
title('temperature from 2:00 PM - 6:00 PM')
hold on
subplot(1,6,2)
Temp_Cal = [20 22 25 25 23]; %Temperature Calgary
y2 = Temp_Cal;
plot(x,y2,'LineStyle',':','color','r','Marker','*','MarkerSize',5)
ylabel('Calgary','Color','blue')
hold on
subplot(1,6,3)
Temp_V = [19 21 20 19 17]; %Temperature Vancouver
y3 = Temp_V;
plot(x,y3,'LineStyle',':','color','r','Marker','+','MarkerSize',5)
ylabel('Vancouver','Color','blue')
hold off
Cris LaPierre
Cris LaPierre le 25 Oct 2020
You do not need the hold on and hold off commands.
Sounds good.
Thanks Cris!!

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 23 Oct 2020

0 votes

I recommend going through MATLAB Onramp. Chapter 9 covers plotting, but it sounds like some of the other chapters would be helpful as well.

1 commentaire

Hi Cris,
Thanks for the feedback. I checked it out and I'm able to do the provided exercises in MATLAB Onramp.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by