How to create large matrix with a pattern of sorts.

8 次查看(过去 30 天)
I wish to create a 64x64 matrix with a patern so it has like 62 0's and 2 1/2's in the 1st row and then 61 0's and 3 1/3's in the 2nd to the 7th, etc. In the worksheet, i was hinted towards using for loops

回答(2 个)

Srivardhan Gadila
Srivardhan Gadila 2020-9-30
Refer to MATLAB Onramp to get started with MATLAB.
The following code might help you:
s = 64;
m = zeros(s,s);
for i = 2:64
m(i-1,s-i+1:end) = 1/i;
end

madhan ravi
madhan ravi 2020-9-30
Since your homework is to use a loop:
M = circshift(fliplr(tril(true(64))) .* [0; 1./(2:64).'], -1, 1);

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by