I want to create a function z=f(a,b)..how can I create like this using the below code?

 Respuesta aceptada

MATLAB documentation tells you how to make functions. Like, to make your "f" function you'd do this:
function z = f(a, b)
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
To call it, you'd do this:
a = Ns;
b = 8;
z = f(a, b)

4 comentarios

Thank you .I try this code,but I have a error like this;
Error: File: kssv.m Line: 103 Column: 1
Function definitions are not permitted in this context.
how to rectify this error?
We would need to see your kssv.m code
clc;
clear all;
close all;
img = imread('cameraman.tif');
c=img';
d=c(:);
[W,L]=size(img);
k=randi(192,1,192);
syms k1 t
for i=1:4
k1=k(((48*i)-47):(48*i));
a1 = symsum(k1*(2^(t-(48*i)+47)),t,((48*i)-47),(48*i));
a2=a1/(2^48);
end
for x=1:2
r(x)=mod(prod(a2*(2^48)+a2(x)),0.4)+3.6;
C(x)=mod(prod(a2*(2^48)+a2(x+2)),1);
end
C1=C(1);
C2=C(2);
for y=1:[W,L]
if y==1
C(y)=C(x);
else
if y~=1&&C(y-1)<0.5
C(y)=0.5*(r(x)*C(y-1));
else
if y~=1&&C(y-1)>=0.5
C(y)=0.5*(r(x)*(1-(C(y-1))));
end
end
end
end
for y=1:[W,L]
if y==1
E1(y)=d(y);
else
E1(y)=mod(d(y)+floor(C(y)*(10^13))+d(y-1),256);
end
end
for y=1:[W,L]
if y==[W,L]
E2(y)=E1(y);
else
E2(y)=mod(E1(y)+floor(C(y)*(10^13))+E1(y+1),256);
end
end
E2=E2';
Q=sum(E2');
Q=sym2poly(Q);
for j=1:192
q=dec2bin(Q,j);
kb=dec2bin(k,j);
end
kb = kb(randi(size(kb,1)),:);
k2=xor(q,kb);
E=[1,(W*L)+24];
E={k2,E2};
k=3;
n=5;
m=(2*k)-2;
n1=k-1;
N=(factorial(m))/(factorial(n1)*factorial(n1));
o = ones(k-1,1) ;
z = zeros(k-1,1) ;
a1 = [o ; z];
v = a1' ;
a = unique(perms(v),'rows');
a=a';
a= a(:, randperm(size(a, 2)))
x1=log2(n/m);
x=ceil(x1);
I=max(x,0);
Ns=N^(I+1);
b=[(m*(2^I)),Ns];
nrows=length(a(:,1));
ncols=length(a);
Nr=nrows/2;
y=ceil(Nr);
o1=ones(y,ncols);
m1=a(1:y,:);
m2=a((y+1):nrows,:);
afinal = zeros(b);
for r=1:nrows
for c=1:ncols
if a(r,c)==0
afinal(Nr*(r-1)+1:Nr*(r-1)+Nr,ncols*(c-1)+1:ncols*(c-1)+ncols) = o1;
else
if(r<3)
afinal(Nr*(r-1)+1:Nr*(r-1)+Nr,ncols*(c-1)+1:ncols*(c-1)+ncols) = m1;
else
afinal(Nr*(r-1)+1:Nr*(r-1)+Nr,ncols*(c-1)+1:ncols*(c-1)+ncols) = m2;
end
end
end
end
R = randperm(size(afinal,1));
R = R(1:n);
S=afinal(R,:);
D(1)=floor(Ns/256);
D(2)=mod(Ns,256);
t=ceil(Ns/8);
c = Ns;
d= 8;
z = f(c, d)
function z = f(c,d)
if ~mod(c,d)
z=0
else
z=d-mod(c,d);
end
end
If you are using R2016a or earlier, you will need to store the code starting from 'function' in the file f.m

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Functions en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by