필터 지우기
필터 지우기

Take two matrices in a folder, take the difference, and save the new matrix to a new folder.

조회 수: 2 (최근 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
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.
Alexander Wang
Alexander Wang 2023년 2월 8일
The two matrices have already been made and are presaved. The matrices are .mat files. I would then want to save it as a .mat file as well to a new folder.
The folder they are in are named "C:\Users\Alex\Desktop\GraphVar\GraphVar_2.03a\workspaces\Winter23_New\data\Matrices GSR" if that helps. If there is any other information you need please don't hesitate to respond.

댓글을 달려면 로그인하십시오.

답변 (2개)

Arif Hoq
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')

Tushar Behera
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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by