Moran Function, in command window print every calculation, and i don't want that

1 次查看(过去 30 天)
Hey guys. I have a problem with my code below, the problem is: when i run it In the command window there are many calculations and the message to each is something like this: Columns 999279 through 999292, and i don't want to display this over and over again. So please Help
function f=Monar(nr_s)
vect_n=[];
vect_S=[];
ok=0;
for i=1:nr_s
fprintf('scalation factor %d ',i)
S=input(' S=')
fprintf('how many photos with scalation number %d does we have? ',i)
n=input(' n=')
vect_S(i)=S;
vect_n(i)=n;
end
D=[0:0.0001:100];
for i=1:length(D)
f(i)=0;
for j=1:length(vect_S)
f(i)= f(i)+vect_n(j)*(1/vect_S(j))^D(i);
end
f(i)=f(i)-1;
if ok==0 & f(i)-0.00001<0
D(i);
ok=1;
end
end
plot(D,f);
end
This code stated from this: (I want all the constants(like n1,n2..,s1,s2..) to be entered from the keyboard)
clear all;
clc;
ok=0;
n1=3;
s1=3;
n2=1;
s2=3/2;
n3=0;
s3=1;
D=[0:0.0001:100];
for i=1:length(D)
f(i)=n1*(1/s1)^D(i)+n2*(1/s2)^D(i)+n3*(1/s3)^D(i)-1;
if ok==0 & f(i)-0.00001<0
D(i)
ok=1
end
end
plot(D,f);

采纳的回答

Star Strider
Star Strider 2019-11-9
Put a semicolon ; at the end of each line you do not want to print to the Command Window.
See: MATLAB Operators and Special Characters for information on this and others.
  2 个评论
Star Strider
Star Strider 2019-11-9
It appears to be ‘D(i)’ here:
D=[0:0.0001:100];
for i=1:length(D)
f(i)=n1*(1/s1)^D(i)+n2*(1/s2)^D(i)+n3*(1/s3)^D(i)-1;
if ok==0 & f(i)-0.00001<0
D(i)
ok=1
end
end
It only ptinrs as ‘ans’, so I just went through and looked for lines without ending semicolons. When I added a semicolon to that line, ‘ans’ disappeared, although ‘ok’ from the line below it continued to print. That was the only one I found in the code you posted.
The other problem could be that when you call your function, that I assume is:
f = Monar(nr_s)
that you did not put a semicolon at the end of that call. Put a semciolon at the end of that:
f = Monar(nr_s);
and the output ‘f’ should not print.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by