How to Create Surface Plot From Cells?
显示 更早的评论
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 个评论
Stephen23
2019-6-5
Austen Thomas
2019-6-5
Adam Danz
2019-6-5
Could you attach dummy data? We're in the dark here.
Austen Thomas
2019-6-5
编辑:Austen Thomas
2019-6-5
Adam Danz
2019-6-5
I'm guessing 1:10 is supposed to be 1,10
Austen Thomas
2019-6-5
Austen Thomas
2019-6-5
编辑:Austen Thomas
2019-6-5
Adam Danz
2019-6-5
Ok. If you're using surf(Z), Z is a [n by m] matrix defining the z (height / color) values of the surface plot while x = 1:n and Z = 1:m.
Judging your loops, would the first surface be defined like this?
Z = [(1:10)',A{1}',B{2}'];
Austen Thomas
2019-6-5
Adam Danz
2019-6-5
" 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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!