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!