필터 지우기
필터 지우기

How to put Multiple Parallel Entries in Vectors?

조회 수: 1 (최근 30일)
Eleazar
Eleazar 2012년 12월 21일
I have q=zeros(20,1) and x=[3;4;5;6;7;8;9;1;2;3;4;5]
If I declare q(x,1)=1 then I get:
q=[1;1;1;1;1;1;1;1;1;0;0;0;0;0;0;0;0;0;0;0].
And if later I apply q(x,1)=q(x,1)+1 then I get:
q=[2;2;2;2;2;2;2;2;2;0;0;0;0;0;0;0;0;0;0;0].
So, using only MATLAB, how can I get with q(x,1)=q(x,1)+1 this result:
q=[2;2;3;3;3;2;2;2;2;0;0;0;0;0;0;0;0;0;0;0] ??
-Ele

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 21일
q = q + accumarray(x, 1, size(q));
  댓글 수: 1
Eleazar
Eleazar 2012년 12월 21일
How did I miss this command?
Thanks a lot!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by