이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
how to create a mean velocity matrix from multiple .dat files and plot the mean profile?
조회 수: 4 (최근 30일)
이전 댓글 표시
Ernest Adisi
2018년 7월 31일
I have a folder of x no of *.dat files. So far I've imported 1 file and reshaped the columns to get matrices for each column. e.g for 1 dat file:
filename='B00049.dat';
delimiterIn= ' ';
headerlinesIn = 3;
A= importdata(filename,delimiterIn,headerlinesIn);
%% Matrices%%%%
c = 214;%columns i
r = 134;%rows j
dt= 0.0005;
x=reshape(A.data(:,1),r,c);
y=reshape(A.data(:,2),r,c);
u=reshape(A.data(:,3),r,c);
v=reshape(A.data(:,4),r,c);
I now want to import multiple files and creat a mean velocity matrix fro u and v then plot a profile. How can this be done ? Thanks
댓글 수: 2
Ernest Adisi
2018년 7월 31일
thanks for the response, i'm trying to create a path to the folder containing all the files then perform a loop in order to make the 4 matrices for each file, then finally create a mean velocity matrix from the average of the last two columns in the 2 dat files. Hope that makes sense
채택된 답변
jonas
2018년 7월 31일
편집: jonas
2018년 7월 31일
files=dir('*.dat') %If files are in current dir, otherwise enter entire path
%%Preallocate some cells
x=cell(1,numel(files))
y=cell(1,numel(files))
u=cell(1,numel(files))
v=cell(1,numel(files))
%%Loop over all files
for i=1:numel(files)
filename=files(i).name
delimiterIn= ' ';
headerlinesIn = 3;
A= importdata(filename,delimiterIn,headerlinesIn);
c = 214;%columns i
r = 134;%rows j
dt= 0.0005;
%%Save results
x{i}=reshape(A.data(:,1),r,c);
y{i}=reshape(A.data(:,2),r,c);
u{i}=reshape(A.data(:,3),r,c);
v{i}=reshape(A.data(:,4),r,c);
end
When you have all the data stored in cells, you can concatenate along the third dimensinon and take the average. I assume all files share the same size?
V = cat(3, v{:});
mean(V,3)
댓글 수: 25
Ernest Adisi
2018년 8월 1일
Yes they are. This works brilliantly. Thanks a lot, can I just ask a further question.
1. for V = cat(3, v{:}); has it concatenated the V matrices so like they are stacked like a 'stack of waffles' for example, then calculates a mean matrix ? and the 3 what does it do please? don't understand the matlab explanation of it
Ernest Adisi
2018년 8월 1일
alright thanks I understand that now. lastly, i'm just wondering what the 'v{:}' in the command V = cat(3, v{:}); is telling matlab
Ernest Adisi
2018년 8월 1일
and also, from the mean matrix can how do i plot a mean profile. i don't if its a contour plot or something else? so it display the different velocity profiles in the regions
Stephen23
2018년 8월 1일
" i'm just wondering what the 'v{:}' in the command V = cat(3, v{:}); is telling matlab"
jonas
2018년 8월 1일
It's difficult for me to plot because I am not really familiar with your data. Nevertheless, I made an attempt. Is that what you want?

[Xq Yq]=meshgrid(0:6:max(x{1}(:)),0:6:max(y{1}(:)));
Vq=griddata(x{1}(:),y{1}(:),V_mean(:),Xq,Yq);
contourf(Xq,Yq,Vq)
Ernest Adisi
2018년 8월 1일
Yes, its that, thank you v.much Jonah. i'm just trying to understand the code but that seems similar to what I need to achieve. Thank you
jonas
2018년 8월 1일
You're welcome. Attempting to understand the code is exactly what you should be doing, so continue with that. The MATLAB documentation is extremely helpful!
The plotting is fairly simple, but looks complex. Just read about meshgrid (creates a grid) and griddata (interpolates scattered data to the grid).
Ernest Adisi
2018년 8월 3일
%% plot mean velocities %%%% V-mean%% [Xq Yq]=meshgrid(0:2:max(x{1}(:)),0:2:max(y{1}(:))); Vq=griddata(x{1}(:),y{1}(:),V_m(:),Xq,Yq);
f1=figure; contourf(Xq,Yq,Vq); xlabel({'x(m)'}) ylabel({'y(m)'}) title('V-mean velcity profile') hcb= colorbar title(hcb,'Velocity[m/s]')
%%%% U-mean%% [Xq Yq]=meshgrid(0:2:max(x{1}(:)),0:2:max(y{1}(:))); Uq=griddata(x{1}(:),y{1}(:),U_m(:),Xq,Yq);
f2=figure; contourf(Xq,Yq,Uq) xlabel({'x(m)'}) ylabel({'y(m)'}) title('U-mean velcity profile') hcb= colorbar title(hcb,'Velocity[m/s]')
this seems to have a problem with the plot, do you have an idea why please?
jonas
2018년 8월 3일
Please make sure your code is formated like this:
[Xq Yq]=meshgrid(0:2:max(x{1}(:)),0:2:max(y{1}(:)));
Vq=griddata(x{1}(:),y{1}(:),V_m(:),Xq,Yq);
f1=figure;
contourf(Xq,Yq,Vq);
xlabel({'x(m)'}) ylabel({'y(m)'})
title('V-mean velcity profile')
hcb= colorbar
title(hcb,'Velocity[m/s]')
%%%%U-mean%%
[Xq Yq]=meshgrid(0:2:max(x{1}(:)),0:2:max(y{1}(:)));
Uq=griddata(x{1}(:),y{1}(:),U_m(:),Xq,Yq);
f2=figure;
contourf(Xq,Yq,Uq)
xlabel({'x(m)'})
ylabel({'y(m)'})
title('U-mean velcity profile')
hcb= colorbar
title(hcb,'Velocity[m/s]')
Seems fine to me, provided that the grid should start at x=0 and y=0. Otherwise, change to:
[Xq Yq]=meshgrid(min(x{1}(:)):2:max(x{1}(:)),min(x{1}(:)):2:max(y{1}(:)));
Other than that, the code looks fine at first glance. What is the error message?
Ernest Adisi
2018년 8월 9일
Hey, can i ask another question please. I trying to change the orientation of the profile,like 90 degree rotation, could you show me how its done please
jonas
2018년 8월 9일
What do you mean? Do you want to just change the view? Then change the first value in the view pair. For example:
set(gca,'view',[90 90]) %
...or do you want to rotate the actual Z-matrix 90 degrees?
B = rot90(A)
this will however crash your script unless you have a square matrix. You probably just want to change the view.
Ernest Adisi
2018년 8월 9일
like as you see in the plot above, the flow direction is top to bottom , but i want it left to right so rotation in z axis. while keeping the x and y the same.
Ernest Adisi
2018년 8월 9일
for example, this rotated anticloclwise 90 degrees but everything else kept the same
jonas
2018년 8월 9일
I dont understand. Do you want the flow direction to be ~0.6-0.7 m in your latest image?
Ernest Adisi
2018년 8월 9일
you're right. It worked. Thank you so much again for all the help. Appreciate it
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
