フィルターのクリア

How to do this efficiently?

2 ビュー (過去 30 日間)
S. David
S. David 2014 年 8 月 9 日
コメント済み: dpb 2014 年 8 月 11 日
Hello all,
I have this variable a[k,m]=max(k*Ts+taup,m*Ts+tauq) for k,m=0,1,...,N-1. I want to find the matrix A where [A]_{k,m}=a[k,m] efficiently. To do so, I define two matrices RowInc and ColInc as
RowInc =(0:N-1)'*ones(1,N);
ColInc =transpose(RowInc);
Then I write
for pp=1:Np
for qq=1:Np
A=max(RowInc*Ts+tau(pp),ColInc*Ts+tau(qq));
end
end
Does this give me what I want?
Thanks
  4 件のコメント
Image Analyst
Image Analyst 2014 年 8 月 9 日
Nothing is in gray. But basically you mean that A=a everywhere. The A and a matrices are identical.
S. David
S. David 2014 年 8 月 9 日
When you shade a part of your writing and then press "{}code" in the toolbar the shaded writing will appear in gray, right?
The (k,m)th element of A is a function of k and m for k,m=0,1,...,N-1.

サインインしてコメントする。

回答 (2 件)

dpb
dpb 2014 年 8 月 9 日
...I want to find the matrix A where [A]{k,m}=a[k,m]..._
A=max(RowInc*Ts+tau(pp),ColInc*Ts+tau(qq));
will end up w/ just a single value for A at the last loop of pp and qq since it overwrites the previous A each iteration. But, I don't believe it does what you want, anyway.
Should be simply
A(A==a);
if I understand the query correctly.
  5 件のコメント
S. David
S. David 2014 年 8 月 9 日
Actually, a is not an array, and I need to compute it. I could have written this:
for kk=0:N-1
for mm=0:N-1
if kk*Ts+taup>mm*Ts+tauq
A(kk+1,mm+1)=kk*Ts+taup;
else
A(kk+1,mm+1)=mm*Ts+tauq;
end
end
end
But N is a large number, e.g. N=2048 and in for loops this takes a while. So, I need to avoid this.
dpb
dpb 2014 年 8 月 9 日
IA, I couldn't figure out what his last comment said (and little of the rest) if after "I have this variable a[k,m]..." there isn't an array a.
Guess I'll leave the field bloodied on this one...

サインインしてコメントする。


dpb
dpb 2014 年 8 月 10 日
OK, from the loop solution one can write
[x,y]=ndgrid(0:N-1,0:N-1);
A=max(Ts.*x+taup,Ts.*y+tauq);
trading memory for the loop. The loop solution could be simplified since there's only a dependence upon kk for the one term and mm for the other, they could be precomputed outside the loops. Preallocating also would help, of course. Not sure how the timings would come out in the end.
  2 件のコメント
S. David
S. David 2014 年 8 月 11 日
編集済み: S. David 2014 年 8 月 11 日
This is exactly what I did, but I wrote
x=(0:N-1)'*ones(1,N);
y=transpose(RowInc);
instead of
[x,y]=ndgrid(0:N-1,0:N-1);
dpb
dpb 2014 年 8 月 11 日
So then what was the question???

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by