Code optimization by way of selective computations
이전 댓글 표시
I have the following code:
clc; clearvars;
Ts = 1e-1; t = 0:Ts:1-Ts
flag = mod(1:length(t),2)
s_t = exp(1i*2*pi*t)
I am looking to only execute the
computation only when the corresponding value for
is logical 1. I wish to do this without iterating as the final vector to process is
long and is about 97% zero values in the result.
채택된 답변
추가 답변 (1개)
Ts = 1e-7; t = 0:Ts:1-Ts;
tic
s_t = exp(1i*2*pi*t(1:2:end));
toc
or if your condition is more complicated:
tic
s_t = exp(1i*2*pi*t(mod(1:length(t),2)==1));
toc
카테고리
도움말 센터 및 File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!