MATLAB Answers

1

Copying arrays from another file

Theophile Garnier さんによって質問されました 2019 年 11 月 8 日
最新アクティビティ dpb
さんによって 回答されました 2019 年 11 月 9 日
Hi,
I am writing a program to copy arrays from a certain amount of matlab files, merge them into one 3D array and analyze them. I am stuck on the part where I need to open each of the files and copy the arrays back to my main program. Does anyone know the syntax for this. To help answer, the files are called PIV_1_0001 to PIV_1_0009 and each contain a u and v array that I must copy back to my main function.
Thank you!

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

dpb
回答者: dpb
2019 年 11 月 9 日

You don't "copy", you just read each file and catenate the (I presume) 2D array to the third dimension of the initial array.
d=dir('PIV_1_*.dat'); % return directory of wanted files--adjust wildcard pattern to suit
tmp=importdata(d(1).name); % read the first file
uv=zeros([size(tmp) numel(d)]); % allocate room for the number files
uv(:,:,1)=tmp; % load first array first plane
for i=2:numel(d) % now do the rest
uv(:,:,i)=importdata(d(i).name);
end

  0 件のコメント

サインイン to comment.



Translated by