3D Plot from Excel data

9 views (last 30 days)
marie lasz
marie lasz on 10 Jun 2021
Edited: Scott MacKenzie on 12 Jun 2021
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
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.
marie lasz
marie lasz on 11 Jun 2021
Edited: marie lasz on 11 Jun 2021
Thanks for your response. I want to use plot3. and I am trying to read the data from excel but the problem I am getting is that it is not plotting correctly. Kindly have a look in the code and see how am I doing (please correct me what and where I am doing wrong).
[x,T,xT] = xlsread('calculations.xlsx','test1','A2:A8');
[x1,T,x1T] = xlsread('calculations.xlsx','test1','B2:B8');
[x2,T,x2T] = xlsread('calculations.xlsx','test1','C2:C8');
[x3,T,x3T] = xlsread('calculations.xlsx','test1','D2:D8');
[x4,T,x4T] = xlsread('calculations.xlsx','test1','E2:E8');
[w,T,wT] = xlsread('calculations.xlsx','test1','F2:F8');
[w1,T,w1T] = xlsread('calculations.xlsx','test1','G2:G8');
[w2,T,w2T] = xlsread('calculations.xlsx','test1','H2:H8');
b=x(:,1);
c=x1(:,1);
d=x2(:,1);
e=x3(:,1);
f=x4(:,1);
g=w(:,1);
h1=w1(:,1);
i=w2(:,1);
plot3(b,c,d,e,f,g,h1,i,'-.')
zlim([0 60]);
xlim([0 8 ]);
ylim([0 2]);
Fig = figure(1);
set(Fig, 'color','white');
xlabel( 'Image Numbers');
ylabel( 'NC');
zlabel('Quality Factors');

Sign in to comment.

Answers (1)

Scott MacKenzie
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:

Community Treasure Hunt

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

Start Hunting!