Home > Enterprise >  Final Mat_Lab Project
Final Mat_Lab Project

Time:12-11

I am working on a final Mat_Lab project and while I have the code written I am having an issue where it won't graph an imported data. the first two parts are as follow:

%parte 1 abre el archivo:
Data = readtable('Proyecto_Final.xlsx');
opts = 'skip Ln1';

%parte 2 graficas lineales:

   hold on;
    figure(1);
    x=Data(:, 1);
    y=Data(:, 2:11);
    plot(x,y,'m*:');
    xlabel('Time(s)');
    ylabel("Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10");
   hold off;

The data in question comes from an Excell file and the following mistakes come through:

Error using tabular/plot (line 217) Tables and timetables do not have a plot method. To plot a table or a timetable, use the stackedplot function. As an alternative, extract table or timetable variables using dot or brace subscripting, and then pass the variables as input arguments to the plot function.

Error in ProyectoFinal (line 17)

plot(x,y,'m*:');

Which I did added under the ylabel as stackedplot (x,y);

CodePudding user response:

You can't access a column of a MATLAB table by the command Data(:, 1), rather you should use Data.Var1 where Var1 is the name of the column.

Using the following test.txt file an MWE (minimum workable example) is provided. Edit this as per your table:

test.txt

1 12 12 47
2 24 19 32
4 45 48 31  
5 54 12 27 
6 68 95 56
7 82 45 56
8 94 36 56
9 102 12 24

MWE:

Data = readtable('test.txt');

hold on;
    figure(1);
    x = Data.Var1
    y = [Data.Var2, Data.Var3, Data.Var4];
    plot(x,y,'m*:');
    xlabel('Time(s)');
    ylabel("Day data")
    legend("Day 1", "Day 2", "Day 3");
   hold off;

Output plot:

enter image description here

Note: I think with the command \ylabel, you are actually trying to produce legends. See the corresponding documentation (Project part 1

Project part 2

Project part 3

Project part 4

Project part 5

figure (1)

graph selection

figure (2)

figure (3)

Project part 6

Project Data

Thanks again for your help and pointers, may these images help you.

  • Related