Matrix Dimensions not agreeing

조회 수: 1 (최근 30일)
Joe Bannen
Joe Bannen 2015년 11월 13일
댓글: Star Strider 2015년 11월 15일
Hi
I am working with the following:
phi = @(ep,r1) exp(-(ep*r1).^2);
ep = 1;
r1=0.1;
S=linspace(0,1);
t=linspace(0,1);
% Randomly Select 10 points from each of S and t.
S_rand = S(sort(randperm(numel(S), 10)));
t_rand = t(sort(randperm(numel(t), 10)));
[S_,t_]=meshgrid(S_rand,t_rand);
X=[S_(:) t_(:)];
D=phi(ep, distm(X,X));
U=bsf(S_,t_,1,1,0.25,0.05);
c=D\U;
I need D to be a 10 x 10 matrix (like U) and not a 100 x 100 matrix as this code is generating. I can't seem to see why this is happening. Any ideas?
Many thanks
Joe

채택된 답변

Star Strider
Star Strider 2015년 11월 13일
Two ideas:
First, it’s best to always completely vectorise your functions unless you intend matrix operations:
phi = @(ep,r1) exp(-(ep.*r1).^2);
Second, we don’t have ‘distm’. I would break it out into its own variable for troubleshooting purposes to be certain it is not creating your (100x100) matrix:
X=[S_(:) t_(:)];
Q1 = distm(X,X) % See What ‘distm’ Returns
D=phi(ep, distm(X,X));
  댓글 수: 6
Joe Bannen
Joe Bannen 2015년 11월 14일
Thanks, that is absolutely fantastic. This is such a great place to learn more about this awesome computer program!
Cheers
Joe
Star Strider
Star Strider 2015년 11월 15일
As always, my pleasure! I appreciate your compliment.
It definitely is! MATLAB Answers is where I learned a lot about MATLAB, both by reading other Answers and by helping to solve problems I would never have encountered otherwise.

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

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by