How to make for loop to make various mathematical operations. Using matrices.
조회 수: 1 (최근 30일)
이전 댓글 표시
clear all clc magic=magic(5); t = zeros(size(magic,1),1); pi = zeros(size(magic,1),size(magic,2)); for i=1:size(magic,1) t(i)=sum(magic(i,:)); pi(i)=magic(i,:)/t(i,1); end
Above is my code I am currently using for testing. My idea is for every values in the row in magic, divide it by sum of that row (AKA it should be divided by 1 number).
댓글 수: 0
답변 (3개)
Purushottama Rao
2016년 12월 16일
편집: Purushottama Rao
2016년 12월 16일
If it is a magic matrix, then its fairly simple..
m=magic(5);
s=sum(m);
ans= m/s(1)
댓글 수: 0
José-Luis
2016년 12월 16일
your_array = magic(5); %don't use a built-in function as a variable name
your_result = bsxfun(@rdivide,your_array, sum(your_array,2));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!