Problem with reshape and Surf plot
Afficher commentaires plus anciens
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 commentaires
Steven Lord
le 26 Juil 2021
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
le 26 Juil 2021
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
le 26 Juil 2021
Nikhil Sapre
le 26 Juil 2021
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
le 26 Juil 2021
ragnor
le 26 Juil 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

