how to save signals in sequence of numbers in '.mat' form?

9 visualizzazioni (ultimi 30 giorni)
I want to save my signals by new name that include 3 datas in 1 '.mat' file.
like this: Annotation1, Annotation2, ...
the problem is 'Annotation' is string and '1' is number and they don't match togther so I used "num2str()" . so, when i run my code which is in for loop and want to save files it just over writing my files or make so many number files from one data.
to solve this this problem i made two random number generator because by one it makes less "mat" files.
in conclusion, i have orgenized audio files, when i do some extractions and want to save them, so i have to save as a random method i sugessted but i can't find which mat file is related to which audio file or (PCG_resampled) ...
here's my code:
ValueOfstageOne = zeros(length(PCG_resampled),1);
ValueOfstageThree = zeros(length(PCG_resampled),1);
for j = 1:length(PCG_resampled)
if assigned_states (j) == 1
ValueOfstageOne (j) = (abs(PCG_resampled(j)))/(abs(PCG_resampled(j)));
end
if assigned_states (j) == 3
ValueOfstageThree (j) = ((abs(PCG_resampled(j)))/(abs(PCG_resampled(j))))*2;
end
end
r = randperm(20,1);
f = randperm(20,1);
save(['Annotation' num2str(r),num2str(f) '.mat'],'ValueOfstageOne','ValueOfstageThree','PCG_resampled')
  4 Commenti
azoma zakari
azoma zakari il 31 Mag 2022
Modificato: azoma zakari il 31 Mag 2022
first of all, thank you for your priceless asnwer!
second of all, I don't want my numbers be random. i have 20 audio files and simply want my out put be like:
Annotation1
Annotation2
.
.
.
Annotation20
that's all, not Annotations with random numbers (like:Annotation1451). I had to choose that method because I didn't know what else I can do.
again thanks for your great help!
Voss
Voss il 1 Giu 2022
@azoma zakari: You mention that you want to "include 3 datas in 1 '.mat' file". Do these "3 datas" correspond to 3 iterations of a loop you have, where, as it is now the 2nd and 3rd iterations overwrite what was done in the 1st iteration? And you would like to have the variables written to the same 20 mat files in each iteration of the loop, but with 3 different variable names inside each mat file (or some other way to distinguish what the variables' values were in the 3 different iterations of the loop)?

Accedi per commentare.

Risposta accettata

Jan
Jan il 1 Giu 2022
Modificato: Jan il 1 Giu 2022
for k = 1:20
...
filename = sprintf('Annotation%02d.mat', k)
save(filename, ...)
end
This creates Annotation01.mat, Annotation02.mat, ... Inserting the leading zero let the alphabetically sorted files be sorted numerically also. To omit the leading zero:
filename = sprintf('Annotation%d.mat', k)
  5 Commenti
Jan
Jan il 1 Giu 2022
Yes, of course you have. This is what you have asked for. Now you explain, that you get, what you have asked for.
I guess, an important detail is missing: you want something else. So please take the time to mention, what exactly you want instead. I cannot guess it.
What about including the code in an additional loop?
for outer_counter = 1:10
for k = 1:20
...
filename = sprintf('Annotation%02d.mat', k + (outer_counter - 1)*20)
save(filename, ...)
end
end
Or:
... your code here
List = dir(fullfile(pwd, 'Annotation*.mat'));
filename = sprintf('Annotation%02d.mat', numel(List) + 1);
save(filename, ...)
This counts how many matching files are in the current folder and uses a new index which is 1 larger.
Please do not let the readers guess, what you want, and do not waste youzr time with explaining, what you do not want.
azoma zakari
azoma zakari il 1 Giu 2022
Modificato: azoma zakari il 1 Giu 2022
sure! I will explain more next time. it was my first question here sorry. thank you so much your answer is great !

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by