I need help rearranging values in a 2D Matrix to create contour plots
1 view (last 30 days)
Show older comments
I need to rearrange UM, VM, and tkeMean to a 2D Matrix and have X,Y value corresponding in the X and Y values match tkeMean, UM, VM. I also need to create contour plots for UM, VM, and tkeMean. When I run my code I get the error "Z must be at least a 2x2 matrix" attached below is my code:
clc;clear;
Uall=[];
Vall=[];
for i=0:798
temp_L=importdata(['Final Project Adaptive PIV.76m7uaui.', num2str(i,'%06d') ,'.txt']);
inst_L=temp_L.data;
Uall(:,i+1)=inst_L(:,3)';
Vall(:,i+1)=inst_L(:,4)';
disp(i);
end
X=inst_L(:,1);
Y=inst_L(:,2);
UM=mean(Uall,2);
VM=mean(Vall,2);
UPrime = Uall-UM;
VPrime = Vall-VM;
TKEall = 0.5*((UPrime.*UPrime)+(VPrime.*VPrime));
tkeMean = mean(TKEall,2);
x = (unique(X));
y = (unique(Y));
[x,y] = meshgrid(x,y);
contourf(x,y,tkeMean)
0 Comments
Answers (2)
Zaitun
on 8 Dec 2022
You can try this code in this section and edit the code like
% x = (unique(X));
% y = (unique(Y));
[x,y] = meshgrid(X,Y); % change the x and y to be X and Y
because the size of x and y is different with tkeMean.
I hope this answer is worth it. I'am wait your respond about it
Voss
on 8 Dec 2022
Try this:
clc;clear;
Uall=[];
Vall=[];
for i=0:798
temp_L=importdata(['Final Project Adaptive PIV.76m7uaui.', num2str(i,'%06d') ,'.txt']);
inst_L=temp_L.data;
Uall(:,i+1)=inst_L(:,3)';
Vall(:,i+1)=inst_L(:,4)';
disp(i);
end
X=inst_L(:,1);
Y=inst_L(:,2);
UM=mean(Uall,2);
VM=mean(Vall,2);
UPrime = Uall-UM;
VPrime = Vall-VM;
TKEall = 0.5*((UPrime.*UPrime)+(VPrime.*VPrime));
tkeMean = mean(TKEall,2);
x = unique(X);
y = unique(Y);
contourf(x,y,reshape(tkeMean,numel(y),[]))
If that doesn't work, change the last line to this:
contourf(x,y,reshape(tkeMean,numel(x),[]).')
If that doesn't work, upload one of your .txt files (using the paperclip button).
0 Comments
See Also
Categories
Find more on Startup and Shutdown 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!