Plotting a graph based on a large table

5 vues (au cours des 30 derniers jours)
Theo
Theo le 30 Sep 2024
Im trying to graph a large 17x17 table and haven't got a clue how to do it, i've managed to import the data from Excel but cant work out how to display the relationship between the x and y axis when there are so many different data entries. Any help would be great, thanks.
  1 commentaire
dpb
dpb le 30 Sep 2024
A more detailed description of the data and what you're trying to display would certainly help...17x17 isn't large at all, it wouldn't seem--that's only 289 points???
As per usual, it would be much simpler to respond to the specific Q? if were to attach the Excel file so could see what it is you have.
Meanwhile, look at stackedplot to see if maybe that doesn't solve much if not all of your problems...

Connectez-vous pour commenter.

Réponses (3)

Steven Lord
Steven Lord le 30 Sep 2024
When you say "haven't got a clue how to do it" does that mean that you know what type of plot you want to create but don't know the command that can create that type of plot, that you don't know what type of plot you want to use to compare the data, or something else?
In the first case, look at the thumbnails on this documentation page. If one of those thumbnails looks like the plot you envision, click on the function name immediately above the thumbnail to go to the documentation page for the function used to create it. Alternately search the documentation for some keywords related to that type of plot. Some types of plots may be provided as functions in other toolboxes, and those plots won't necessarily show up on that page, but you may be able to find those functions with a documentation search.
In the second case, looking through that documentation page may help inspire you or you may need to take a step back and consider what insight you're trying to glean from that picture. What do you hope the picture will tell you about the data?
In the third case, could you clarify what type of help you're hoping MATLAB Answers readers can provide?

Image Analyst
Image Analyst le 30 Sep 2024
Modifié(e) : Image Analyst le 30 Sep 2024
Theo, would using imshow or imagesc work?
data = readmatrix(filename);
imshow(data, []);
axis('on', 'image')
xlabel('Column');
ylabel('Row');
colorbar;
If you want line plots, have you tried plot? What is the x value? Just the column number or row number of the table?
data = readmatrix(filename);
[rows, columns] = size(data)
for row = 1 : rows
y = data(row, :); % Extract this one row from the table.
plot(y, '.-', 'LineWidth', 2, 'MarkerSize', 12);
hold on;
end
grid on;
ylabel('Y Values');
xlabel('Index')
title('Data Plotted')
See a variety of ways to plot data here: https://www.mathworks.com/products/matlab/plot-gallery.html
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

Arjun
Arjun le 1 Oct 2024
Hi @Theo,
I see you need help on plotting your data contained in a table by using MATLAB code.
There are various type of plots which MATLAB offers like line plots, scatter and bubble charts, data distribution plots, polar plots and many more. As a first step you can consider visiting the following link to decide the type of plot you need.
Once you have decided which plot to work with there are various properties you can tweak like “xlabel”, “ylabel”, “title”, “legend “ and many others depending on the type of plot you choose. You can view the properties by clicking on the hyperlink of the selected plot in the above documentation link.
Also, you can refer to the following example workaround for plotting your data:
% Data Loading phase
filename = 'Your excel file name.xlsx';
sheet = 1;
data = readtable(filename, 'Sheet', sheet);
% Data conversion from table to array
dataArray = table2array(data);
% Determine the dimensions of the data array
[numRows, numCols] = size(dataArray);
% Create a new figure
figure;
% Hold is used to draw multiple lines on a single plot
hold on;
% Plotting Phase- Plot each column as a separate line
for i = 1:numCols
plot(1:numRows, dataArray(:, i), '-o', 'DisplayName', ['Series ', num2str(i)]);
% Display name will be used in the legend, -o is solid line with
% circular markers
end
% Customize the various properties of the plot
xlabel('Row Index');
ylabel('Data Value');
% xlabel and ylabel are used to add axis information to graph
title('Line Plot of 17x17 Data Table');
% title will give a description to the graph
legend show;
% Legend will contain information about various lines which are drawn.
grid on;
hold off;
Here are some more resources to explore:
I hope this will help!

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by