Looping matrice column by subtraction
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have a 84x7 matrices. On the entire column 2 and 4, they need to be subtracted from higher number - lower and loop through the whole 84 rows and put them into a new 84x1 vector. How can this be done? let 4x4 matrix a = [x 3 2 y; x 4 1 y; x 1 6 y; x 2 7 y; x 5 1 y;
b= [3-2 4-1 6-1 7-2 5-1]
b= [1 3 5 5 4 ]
댓글 수: 1
madhan ravi
2018년 10월 21일
A small example? And your desired output?
채택된 답변
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
EDIT 2
a = randi([0 9],84,7) %fake data to test
a1=a(:,2) %column you want to extract
a2=a(:,5) %column you want to extract
a=[a1 a2] %two columns stored in a matrix , sorry I missed this line which caused the error
idx = find(a1<a2)
a(idx,:)=fliplr(a(idx,:))
b = a(:,1) - a(:,2) % as column vector
b1 = b' %row vector
댓글 수: 12
madhan ravi
2018년 10월 21일
if it doesn't meet your requirement let know
Young Lee
2018년 10월 21일
Sorry It doesnt work,
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
See edited answer now , no need loop to attain the desired result
Young Lee
2018년 10월 21일
nope ,
madhan ravi
2018년 10월 21일
It’s like you gave in the example right? Am I missing something?
here's code I have used , I figured out all the odd rows were wrong in value as well
x = myreesult2 %EDITED a1= x(:,2); a2= x(:,5); idx = find(a1<a2); %its column 2 & 5 out of 84x7 matrice x(idx,:)=fliplr(x(idx,:)); b = x(:,2) - x(:,5) % as column vector
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
use abs(the_value) to get positive result, if you don’t want to use abs() upload the matrix which you are testing because as you can see it works very well for the example you gave here
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
Can you upload x(:,2) & x(:,5) datas here so that it can be tested
Young Lee
2018년 10월 21일
sure, have look on a1 & a2
madhan ravi
2018년 10월 21일
check the edited code now
Young Lee
2018년 10월 21일
thanks for your patience and help :)
madhan ravi
2018년 10월 21일
편집: madhan ravi
2018년 10월 21일
Anytime:)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
