How do I create multiple figure of cwt in for loop and save them on folder

조회 수: 2 (최근 30일)
Hi everyone!
I record data from emg sensor and segment the signal. I want to convert signal in cwt figure and save them as a picture my example file contain 2560*46 (46 figures).
This is my code and file
load Data_segment.mat
%% Normalized frequency (*pi rad/sample)
frequencyLimits = [0 1];
voicesPerOctave = 8;
%% Convert to cycles/samples
frequencyLimits =frequencyLimits/2;
path = 'C:\Users\payusan\Matlab\BB\cwt\AI\Dataset_creation\CWT_creation' ;
myfolder = 'output_CH1' ;
folder = mkdir([path,filesep,myfolder]) ;
path = [path,filesep,myfolder] ;
for k = 1:length(Data_segment(end,:))
for i = 1 : length(Data_segment(:,end))
for j = 1 : length(Data_segment(end,:))
figure(j)
frequencyLimits(1) = max(frequencyLimits(1),...
cwtfreqbounds(numel(Data_sgement(:,i))));
[WT,F]= cwt(Data_segment(:,i), ...
'VoicesPerOctave',voicesPerOctave, ...
'FrequencyLimits',frequencyLimits);
pcolor(1:numel(Data_segment(:,i),log2(F),abs(WT)));
shading interp;
end
end
temp=[path,filesep,'seg_',num2str(k),'.jpg'];
saveas(figure(k),temp);
end
How do I fix this code.
  댓글 수: 4
KSSV
KSSV 2022년 4월 8일
We cannot run the code as all the variables are not given,
Unrecognized function or variable 'frequencyLimits'.
Error in Junk (line 14)
frequencyLimits(1) = max(frequencyLimits(1),...
Note that pcolor needs matrix as input. In your case it is not, so error popped out.
saratt Ratana-Ubol
saratt Ratana-Ubol 2022년 4월 8일
sorry, about that I forgot to put others valuable. I already fix it

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

답변 (1개)

KSSV
KSSV 2022년 4월 8일
May be you need th add the below shown line after loading the data from mat file.
load Data_segment
Data_segment = New_data ;
  댓글 수: 1
saratt Ratana-Ubol
saratt Ratana-Ubol 2022년 4월 8일
편집: saratt Ratana-Ubol 2022년 4월 8일
I already try that one this is my full code of this part.
D = load('C:\Users\payusan\Matlab\BB\cwt\AI\Mat_file_dataset\label_0\2.mat');
% Signal_segmentation
data = D.CH1;
N_max=length(data);
n_window=2560;
overlap_win=-1;
max_count = ceil((length(data)-n_window)/(n_window-overlap_win))+1;
new_data = zeros(max_count,n_window);
n_start=1;
for count = 1:max_count
n_end = n_start + n_window - 1;
if n_end > N_max
new_data(count,1:N_max-n_start+1) = data(n_start:N_max);
else
new_data(count,:) = data(n_start:n_end);
end
n_start = n_end-overlap_win;
end
%% Normalized frequency (*pi rad/sample)
frequencyLimits = [0 1];
voicesPerOctave = 8;
%% Convert to cycles/samples
frequencyLimits =frequencyLimits/2;
%%
Data_segment = new_data';
path = 'C:\Users\payusan\Matlab\BB\cwt\AI\Dataset_creation\CWT_creation' ;
myfolder = 'output_CH2' ;
folder = mkdir([path,filesep,myfolder]) ;
path = [path,filesep,myfolder] ;
for k = 1:length(Data_segment(end,:))
for i = 1 : length(Data_segment(:,end))
for j = 1 : length(Data_segment(end,:))
figure(j)
frequencyLimits(1) = max(frequencyLimits(1),...
cwtfreqbounds(numel(Data_segment(:,i))));
[WT,F]= cwt(Data_segment(:,i), ...
'VoicesPerOctave',voicesPerOctave, ...
'FrequencyLimits',frequencyLimits);
pcolor(1:numel(Data_segment(:,i),log2(F),abs(WT)));
shading interp;
end
end
temp=[path,filesep,'seg_',num2str(k),'.jpg'];
saveas(figure(k),temp);
end

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

카테고리

Help CenterFile Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by