a = randi(50,600,9);
mx = randi(50,60,1);
q = bsxfun(@minus,reshape(a(:,7),10,[]),mx);
q = reshape(q,[],1);
After reshaping and cutting the variable 'a' into 10 blocks I want the first mx value to be subtracted from the first block of ten, the second mx value from the second block of 10, the third mx value from the third block of 10 and so on.... How can I implement these changes in my bsxfun function?
thanks

댓글 수: 7

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 1일
What is the problem with your code?
AA
AA 2014년 12월 1일
편집: AA 2014년 12월 1일
  • bold * if mx is= 16311440404823233043 and the first ten rows of a in column 7 are 414674632514284849 then I want 16 to be subtracted from 414674632514284849
AA
AA 2014년 12월 1일
31 should be subtracted from the second block of tens, 14 from the third block of tens, 40 from the fourth block of tens and so on.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 1일
This is not clear for me
Stephen23
Stephen23 2014년 12월 1일
After dividing every tenth a value, what happens after mx(10), when there are still 500 a values remaining but no mx values left? Ten blocks of ten makes 100 values, but a(:,7) contains 600... please advise us on what should happen with these remaining values!
you are right. I forgot to mention the condition that the rows of variable a are always a multiple of mx/mn. Thus
a = randi(50,600,9);
mx = randi(50,60,1);
mn = randi(50,60,1);
I wish to subtract mx(1) from the first ten consecutive values of a. q(1:10) = a(1:10) - mx(1) q(11:20)=a(11:20)-mx(2) ... q(591:600)=a(591:600)-mx(60).
Stephen23
Stephen23 2014년 12월 1일
PS: Is there a purpose to creating a huge array a and then using only the seventh column from it?

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

 채택된 답변

Stephen23
Stephen23 2014년 12월 1일
편집: Stephen23 2014년 12월 1일

1 개 추천

Using the arrays that you specified in your most recent comment:
a = randi(50,600,9);
mx = randi(50,60,1);
mn = randi(50,60,1);
b = reshape(a(:,7),10,[]).';
q = bsxfun(@minus,b,mx);
%q = bsxfun(@rdivide,q,mx-mn);
%q = reshape(q.',[],1);

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 12월 1일
편집: Andrei Bobrov 2014년 12월 1일

1 개 추천

a = randi(50,600,9);
mx = randi(50,60,1);
a7 = reshape(a(:,7),10,[]);
out0 = bsxfun(@minus,a7,mx(:)');
out = out0(:);
or
out = a(:,7) - mx(ceil((1:size(a,1))/numel(mx)));

카테고리

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

태그

질문:

AA
2014년 12월 1일

편집:

2014년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by