Take two matrices in a folder, take the difference, and save the new matrix to a new folder.
3 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone, I am new to MatLab and am trying to make a script that will automatically take two specific matrices, take the difference between them as a new matrix, and save that matrix to a new folder.
For example, I have two matrices for one subject named S01_p1 and S01_p2. I would like to form a new matrix from subtracting S01_p1 from S01_p2 and then subsequently save that new matrix in another folder.
Is there any guidance you can provide? I'm presuming it has something to do with a for loop. Sorry if I'm unclear.
2 件のコメント
Tushar Behera
2023 年 2 月 8 日
編集済み: Tushar Behera
2023 年 2 月 8 日
Can you please elaborate from where you want extract these two matrices, is it an excel file or an ASCII file?
Also in the new folder to which format you want to save it to? Provide more details on what you want to do.
回答 (2 件)
Arif Hoq
2023 年 2 月 8 日
S01_p1=10:2:20;
S01_p2=1:6;
out=S01_p2-S01_p1; % out is your output
% C:\Users\Documents\New folder is your folder directory
yourdirectory='C:\Users\Documents\New folder\myfile.mat'; % myfile.mat is your matlab file name
save(yourdirectory,'out')
0 件のコメント
Tushar Behera
2023 年 2 月 8 日
編集済み: Tushar Behera
2023 年 2 月 8 日
Hi Alexander,
I believe what you want to do here is extract two matrices "S01_p1" and "S01_p2" from their respective ".mat" files and then subtract them and save the result in a new folder.
In order to achieve the above workflow, you can use the "load" function to load the two variables into the workspace and perform your operations upon them. Save them to a separate location using the "save" function. For example:
% Load the two matrices from the .mat files
load('path/to/folder/file1.mat', 'S01_p1');%C:\Users\Alex\Desktop\GraphVar\GraphVar_2.03a\workspaces\Winter23_New\data\Matrices can be replaced with path/to/folder
load('path/to/folder/file2.mat', 'S01_p2');
% Subtract the two matrices
result = S01_p1 - S01_p2;
% Create a new folder if it does not exist
if ~exist('path/to/newfolder', 'dir')
mkdir('path/to/newfolder');
end
% Save the result to a new .mat file in the new folder
save('path/to/newfolder/result.mat', 'result');
I am assuming you have named the two ".mat" files as file1 and file2.
I hope this resolves your question.
Regards,
Tushar
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!