matlab program for getting results of all inputs sets in one column

조회 수: 2 (최근 30일)
reshdev
reshdev 2014년 8월 22일
답변: Hikaru 2014년 8월 22일
Hello,
i want to run given below program for n set of inputs. example of input sets-
set 1. f= 7, c0= 1, r0= 3
set 2. f= 9, c0= 2, r0= 4
Every input set will generate 5*5 output matrix as t=5
Then how can i get actual output in column in command window as- For example,
output = output for input set1(matrix of 5*5)
output for input set2(matrix of 5*5)
.
.
output for input set n(matrix of 5*5)
function poster
t= 5;
f = input ('Enter d0 :');
c0= input ('Enter c0 :');
r0 = input ('Enter r0 :');
t=t-1;
M = zeros(t);
for k = 1:f
p = randperm(t);
for s = 1:t
M(p(s),s) = M(p(s),s) + 1;
end
end
M = [M(:,1:c0-1),zeros(t,1),M(:,c0:t)];
M = [M(1:r0-1,:);zeros(1,t+1);M(r0:t,:)];
M(1:(t+2):(t+1)*(t+1))= 0;
disp(M);
end

채택된 답변

Hikaru
Hikaru 2014년 8월 22일
You have to define n as an input to the function poster. I added outer for loop, there might be better ways, but if n is small and speed is not a concern, this is good enough.
function poster(n)
t= 5;
t=t-1;
output = zeros(n*5,5);
for ii = 1:5:5*n
M = zeros(t);
f = input ('Enter d0 :');
c0= input ('Enter c0 :');
r0 = input ('Enter r0 :');
for k = 1:f
p = randperm(t);
for s = 1:t
M(p(s),s) = M(p(s),s) + 1;
end
end
M = [M(:,1:c0-1),zeros(t,1),M(:,c0:t)];
M = [M(1:r0-1,:);zeros(1,t+1);M(r0:t,:)];
M(1:(t+2):(t+1)*(t+1))= 0;
output(ii:ii+4,:) = M;
end
disp(output);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by