How do I plot table with subplot?

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 Commenti

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
You do not need the hold on and hold off commands.
Sounds good.
Thanks Cris!!

Accedi per commentare.

Risposte (1)

Cris LaPierre
Cris LaPierre il 23 Ott 2020

0 voti

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 Commento

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

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by