I need help rearranging values in a 2D Matrix to create contour plots

1 view (last 30 days)
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)

Answers (2)

Zaitun
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
  1 Comment
Manuel Salazar
Manuel Salazar on 8 Dec 2022
tkeMean is a 6624x1 double so i used the reshape function to mold it into a 2x2 matrix. When I applied the reshape function to tkeMean it became a 3312x2 double. Now when I run the code I get the error "The size of X must match must match the size of Z or the number of columns of Z". x is a 6624x6624 double. Here is my current 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);
A = tkeMean;
B = reshape(A, [], 2);
x = (unique(X));
y = (unique(Y));
[x,y] = meshgrid(X,Y);
contourf(x,y,B)

Sign in to comment.


Voss
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).

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!