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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Hikaru
Hikaru il 22 Ago 2014
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

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by