tic;
load 'CCA_result.mat';
CleanData1= CleanData1';
rows = size(CleanData1);
Result_cpei = zeros(1,rows(1));
for N = 1:1:rows
tmp=CPEI(CleanData1(N,:),0);
Result_cpei = [Result_cpei tmp];
save ('CPEI','Result_cpei');
end
The output is not a matter since I got the right output. The issue is can this code to be vectorized?

댓글 수: 4

per isakson
per isakson 2017년 2월 14일
편집: per isakson 2017년 2월 14일
  • looks wrong: &nbsp rows = size(CleanData1). &nbsp Is rows supposed to be scalar?
  • what's &nbsp CPEI ?
M O
M O 2017년 2월 14일
Thanks for your comment and answer. Yup 'rows' supposed to be scalar and I got nothing error for this.
CPEI is a function in matlab for Qeeg feature extraction. The long term is Composite Permutation Entropy Index (CPEI).
Jan
Jan 2017년 2월 14일
편집: Jan 2017년 2월 14일
@M O: Yes, you do not get an error for for N=1:1:[a,b], but most likely this will not do what you expect. Please specify, if you want:
rows = size(CleanData1, 1)
% or
rows = size(CleanData1, 2)
% or
rows = numel(CleanData1, 1)
The created file "CPEI.mat" is overwritten in each iteration. This is not useful. Please write a clean code, which does exactly, what you want, before starting to optimize the speed by a vectorization.
M O
M O 2017년 2월 15일
Ohh..thank you..so because of that my code getting slow..?
Really thanks.

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

 채택된 답변

Jan
Jan 2017년 2월 14일
편집: Jan 2017년 2월 14일

1 개 추천

Start with avoiding to re-create the formerly pre-allocated output and do not overwrite the output file in each iteration:
Data = load('CCA_result.mat'); % Avoid dynamic creation of variables
CleanData1 = Data.CleanData1';
rows = size(CleanData1, 1); % Guessed, perhaps you want NUMEL or the 2nd dim
Result_cpei = zeros(1, rows); % Pre-allocation
for N = 1:rows
Result_cpei(N) = CPEI(CleanData1(N,:),0); % Write ionto pre-allocated array
end
save('CPEI.mat', 'Result_cpei');
If this can be vectorized depends on the contents of the function CPEI. If this function accepts a array as input, the code can be simplified to:
Data = load('CCA_result.mat');
CleanData1 = Data.CleanData1';
Result_cpei = CPEI(CleanData1,0);
save('CPEI.mat', 'Result_cpei');

댓글 수: 1

M O
M O 2017년 2월 15일
편집: M O 2017년 2월 15일
Here I attached the output of the code that you gave it to me. I want this. But its already vectorized or not? Because this code is running faster than mine previously.
But if I run this code, Its only show 1 value only.
Data = load('CCA_result.mat');
CleanData1 = Data.CleanData1';
Result_cpei = CPEI(CleanData1,0);
save('CPEI.mat', 'Result_cpei');
Anyway thanks for the code, and need some more clarification on this.
Thank you.

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

M O
2017년 2월 14일

댓글:

M O
2017년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by