Change localization of files

3 ビュー (過去 30 日間)
Rita Barnabé
Rita Barnabé 2021 年 11 月 7 日
コメント済み: Jan 2021 年 11 月 8 日
Hi! I grouped the filenames according to a certain characteristic and now I wanted to save each file in a folder of the respective group.
I tried this but the code is not saving the files on the groups G1,G2,... in the path
G = {G1 G2 G3 G4 G5 G6};
path="C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\S1.mat";
cd
fileList = dir(fullfile(path));
AllFilenames = {fileList.name};
F_matrix = AllFilenames(:,3:end)';
F_matrix = convertCharsToStrings(F_matrix);
N=length(F_matrix);
% Group by name
% for i=1:6
%
% C_G{i} = find(ismember(F_matrix,G{i}));
% Group{i}=F_matrix(C_G{i});
% end
for j=1:(N-2)
cd(path)
%Read data
file=fileList(j+2).name;
load(file)
if 1i == 1
C_G{1} = find(ismember(file,G{1}));
load(file)
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G1'
save file
elseif 1i ==2
C_G{2} = find(ismember(file,G{2}));
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G2'
save file
elseif 1i == 3
C_G{3} = find(ismember(file,G{3}));
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G3'
save file
elseif 1i == 4
C_G{4} = find(ismember(file,G{4}));
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G4'
save file
elseif 1i == 5
C_G{5} = find(ismember(file,G{5}));
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G5'
save file.mat
elseif 1i == 6
C_G{6} = find(ismember(file,G{6}));
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G6'
save file
end
end
  2 件のコメント
Steven Lord
Steven Lord 2021 年 11 月 7 日
load(file)
cd 'C:\Users\35191\OneDrive - Universidade de Aveiro\Emotional transition - recognition\G1'
save file
This loads the file whose name is stored in the variable named file, changes directory, then saves a file named file (not a file whose name is stored in the variable named file.)
save(X) % Save to the file whose name is stored in the variable x
save X % Save to the file whose name is X, equivalent to
save('X') % Save to the file whose name is X

サインインしてコメントする。

採用された回答

Jan
Jan 2021 年 11 月 7 日
編集済み: Jan 2021 年 11 月 7 日
if 1i == 1
This not true in any case. 1i is the imaginary unit. sqrt(-1) is not equal to 1 in any case. It is not 2,3,4,5,6 also. So non of the if branches will be entered.
Do you mean "j" instead of "1i"?
What is the purpose of the code? "save file" stores all variables of the current workspace in a file called "file.mat". Is this useful?
What is the contents of G1, G2, ...?
I assume, that the code can be simplified. Maybe:
BaseFolder = ['C:\Users\35191\OneDrive - Universidade de Aveiro\', ...
'Emotional transition - recognition'];
data = load(fullfile(BaseFolder, 'S1.mat');
fileList = dir(fullfile(BaseFolder, '*.mat'));
fileList = setdiff(fileList, {'.', '..'});
for k = 1:6
... % Something which uses the cell G?!
file = fileList(k);
save(fullfile(BaseFolder, sprintf('G%d', k), file), '-struct', 'data');
end
  3 件のコメント
Jan
Jan 2021 年 11 月 8 日
Is "S1.mat" a diretory?
What are "sequences"?

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by