Problem with reshape and Surf plot
이전 댓글 표시
Hello MATLAB Community,
I have the following script and data where i would like to plot a 3d Surface and it works well for some data and it doesn't work because of the dimensions in some cases. Can someone please suggest where is the mistake in the script and how to fix it?
opts = detectImportOptions('Data123.xlsx');
opts = opts.setvartype('Y','double');
opts = opts.setvartype('Z','double');
% Load data
data = readtable('Data123.xlsx', opts);
data.Properties.VariableNames = ["X","F_sw","Y","Z"];
% order the data
data = sortrows(data,["X","Y"]);
X = unique(data.X);
Y = unique(data.Y);
Z = reshape(data.Z,[length(Y),length(X)]);
% View
figure(1)
scatter3(data.X,data.Y,data.Z,12,[1 0 0],"filled","MarkerEdgeColor",[0 0 0])
hold on
s = surf(X,Y,Z,"FaceColor",'interp');
hold off
댓글 수: 6
Steven Lord
2021년 7월 26일
What does "does not work" mean?
- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support using the telephone icon in the upper-right corner of this page so we can investigate.
Star Strider
2021년 7월 26일
Exploring the data with:
[X,ix1] = unique(data.X)
seg_len = diff([ix1;numel(data.X)])
produces results: [32; 56; 56; 39]
It is going to be difficult to use reshape with that and get any consistent results.
.
ragnor
2021년 7월 26일
Nikhil Sapre
2021년 7월 26일
I see a error in the way you're using reshape
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
You are trying to reshae the Z array into a matrix thant changes the number of elements. Please read the dosucmentation on reshape. Also, please let give more details on what you're trying to achieve here.
ragnor
2021년 7월 26일
ragnor
2021년 7월 26일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

