How to Create Surface Plot From Cells?

10 views (last 30 days)
I am trying to creat a 2D colored surface plot, but I cannot get it to work.
I have two different cells which come from a .mat file and one vector. The vector V must have 37 values and the two cells are 1 x 37.
clc, clear
% Load Data
x = load('datasamp.mat');
V = x.v; %
A = x.as;
B = x.bs;
n=1;
for i = 1:37
while n <= length(A)
n = n + 1;
V(i) = 1:37
Z = [V; A(i); B(i)];
end
Z = [V;A;B];
surf(Z)
I know I can convert the cells to a matrix using cell2mat, but this has only caused more problems.
The first cell in A corrsponds to values taken at V(1) and the second to taken at V(2) and so on... I want it to plot all the data for V(i) for both A and B the problem is that each cell in A and B are 1000 data points so these are A(i) = 1x1000 and B(i)=1000x1. So i need V(i) to remain constant for all those points which i tried to do with a while loop and then move on to the next so say V(2) and do the same thing .
Does anyone know a way to get the data from the cells to create the surface plot with V on the x-axis A on the Y-axis and B used for the color bar scale?
  10 Comments
Austen Thomas
Austen Thomas on 5 Jun 2019
I currently don’t have my desktop in front of me. But as long as the size of each cell is the same it should work except B should be B{1} for the first interval.
Does surf(Z) run without any issue? Even thought the data is in a cell or does it need to be converted to a matrix still to run?
Adam Danz
Adam Danz on 5 Jun 2019
" But as long as the size of each cell is the same it should work"
Yes, I can make it work, easily. By "work" I mean it doesn't break. But that doesn't mean it's doing what you want it to do.
"...except B should be B{1} for the first interval."
Right, my bad (typo).
"Does surf(Z) run without any issue? Even thought the data is in a cell or does it need to be converted to a matrix still to run?"
It needs to be a matrix. In my example above, I use curley brackets to extract the matrix from the cell array.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 5 Jun 2019
Based on the discussion in the comments under the question, I think this is the approach you're looking for. It works (i.e. there are no errors). But you should check that this works on a conceptual level.
A = {rand(1,10), rand(1,10), rand(1,10)};
B = {rand(10,1), rand(10,1), rand(10,1)};
V = 1:numel(A{1});
Z = [V',A{1}',B{1}];
figure();
surf(Z)
The second part could be put in a loop if you want to generate one surf() for each element in A & B.
  9 Comments
Adam Danz
Adam Danz on 6 Jun 2019
That truncates the data so you never see what's happening past the 1000th data point. Maybe that's sufficient for what you're doing but why throw out everything past the 1000th data point? It doesn't sounds like a good idea. Again, this decision needs to be made at a conceptual level. What are you trying to show with the data?
It's like if a movie is too long and as the editor, you shorten it by merely stopping the movie at the 1-hour mark in the middle of a scene as opposed to cutting a fiew scenes here and there so people get to see the ending.
Another example: Let's say I'm plotting hourly weather measurements from Jan 1,1990 to June 6,2019. Your suggestion would merely cut all data after Jan 24, 1990. My suggestion would cut a few days here and there but you'd still have a data that spans those 19+ years.
Austen Thomas
Austen Thomas on 6 Jun 2019
The data is meant to show the spectral density on the color map for a changing voltage and frequency. Where voltage is on the Xaxis frequency on the Y. Which will allow the viewer to see the greatest intensity for a given voltage and frequency. Where the X axis will be 0-300 and y will be 1000-25e6

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!