3D Plot from Excel data
9 views (last 30 days)
Show older comments
Hello beautiful people;
I have a data in Excel file where I have different images and their NC values against different quality factors. I want to plot it in 3D where at y-axis ---NC values, x-axis -- Images and at z-axis it should be Q.F. Any guidance will be helpful for me. I know how to plot 2D but I don't have any idea How I should plot z-axis where there are different quaulity factors and every quality factor is a column against every image number.Here is the dummy data.
thanks in advance.
2 Comments
Scott MacKenzie
on 10 Jun 2021
Edited: Scott MacKenzie
on 10 Jun 2021
First, you need to decide on a type of plot that might suit your data. See Types of MATLAB Plots for a good summary of your options. There are plenty of coding examples as well. Probably, you'll begin by using MATLAB's readmatrix or readtable command to get your data into a matrix variable. Then, just use code from one of the examples to plot your data.
Answers (1)
Scott MacKenzie
on 11 Jun 2021
Edited: Scott MacKenzie
on 12 Jun 2021
OK, let's work with plot3. The relationships in the data might not be a suited to plot3, but this is a reasonable start.
It's hard tell what the plot will look like, since you did not provide the spreadsheet with your question (and I'm too lazy to type in the values shown in the image).
The following code uses plot3 with data similar in organization to your data. The values vary between 0 and 1, like your data, so that's good. To run this with your data, uncomment the 2nd line and remove the assignment for z that follows.
Note that xlsread is "not recommended". It's better to use readmatrix.
Below, I'm just using a test matrix of random data, so the plot looks a bit crazy. Hopefully, your data will yield a nicer looking plot.
% read your data (7x8) like this
%z = readmatrix('calculations.xlsx', 'sheet', 'test1', 'range', 'A2:H8');
% test data (7x8) for this example
z = rand(7,8);
% plot3 requires three vectors of data
% convert to matrix z to vector Z
Z = z(:);
% build vectors for X and Y (same size as Z)
nRow = size(z,1); % number of rows in z
nCol = size(z,2); % number of columns in z
X = repmat(1:nRow, 1, nCol);
Y = repmat(1:nCol, 1, nRow);
% plot Z in 3D as a function of X and Y
plot3(X,Y,Z);
zlim([0 1]); % Z varies from 0 to 1
xlim([0 7]); % 7 rows
ylim([0 8]); % 8 columns
set(gcf, 'color','white');
xlabel( 'Image Numbers');
ylabel( 'NC');
zlabel('Quality Factors');
But, consider this as well. Your data may be better suited to a 2D chart with your 3rd dimension simply being different lines in the 2D chart. Here's the general idea:
plot(z');
xlabel('Image');
ylabel('NC');
labels = {'Q.F.10', 'Q.F.30', 'Q.F.50', 'Q.F.51', 'Q.F.53', 'Q.F.54', 'Q.F.55', };
legend(labels);
Again, this looks a bit crazy because the data are just random numbers.
You could, of course, transpose (actually, untranspose -- z is transposed in the example above) the data in z to have the QF categories along the x-axis and the Image numbers in the legend.
Instead of lines, you might want bars. By changing plot to bar above, here's the result:
Add the property 'stacked' and here's yet another possibility:
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!