i need to code speed ..anyone can help me? Getting rid of the loop would be a good start

조회 수: 1 (최근 30일)
v=[1 0 0 1];
d=[0.3 0 0 0.4]
d = 1×4
0.3000 0 0 0.4000
n="lp";
count=1;
gg=find(v)
gg = 1×2
1 4
clear b
g={'Cycle n.',count}
g = 1×2 cell array
{'Cycle n.'} {[1]}
j=1; %
j = 1
for h=1:numel(gg)
b{j,h}={[g,gg(h),d(gg(h))]};
end
  댓글 수: 6
pipor
pipor 2023년 9월 4일
편집: pipor 2023년 9월 4일
because I'm working on a laptop and on a lot of data it happened that I got the error about the memory..hence thinking about not making three-dimensional matrices
however I am modifying the code..maybe I make it clearer
Bruno Luong
Bruno Luong 2023년 9월 4일
편집: Bruno Luong 2023년 9월 4일
But you have very bad start. This data organization is awful. We warn you, with such data you'll have speed, memory, and coding problems later.

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

채택된 답변

Bruno Luong
Bruno Luong 2023년 9월 4일
clear
v=[1 0 0 1];
d=[0.3 0 0 0.4];
count=1;
gg=find(v);
g={'Cycle n.',count};
j=1;
clear b
for h=1:numel(gg)
b{j,h}={[g,gg(h),d(gg(h))]};
end
% you want horrible code to store horrible data, here we go
bb = num2cell(num2cell([ repmat(g,[numel(gg) 1]) num2cell([ gg' d(gg)' ])], 2)');
isequal(bb,b)
ans = logical
1
  댓글 수: 1
pipor
pipor 2023년 9월 4일
you want horrible code to store horrible data, here we go :D
thank but i write :"however I am modifying the code..maybe I make it clearer"
however I accept your work

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by