using functions
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am a beginner in using matlab and I would like some help.I have a main program and two other functions used in this program. I use matlab 2008. I would like to ask what I must type and where (command window?) to take my results? Also, where must I write all these functions (like a m-file?)? I give you the structure of my code.
function []=Program_1();
clc;echo off;close all;
A=[ 30,31,12, 9,
17,12,25,10,
12, 8,17, 9,
31,12,26,22];
A=double(A);B=A;
disp('original image matrix');disp(A);
image_depth=31;tones=8;
B=My_plot(A,tones);% B holds grey-tone values only
value=1;
switch value
case 1
WW=20;WL=20;
B=My_simple_window(A,image_depth,tones,WW,WL);
case 2
gray_val=5;im_val=21;
B=My_broken_window(A,image_depth,tones,gray_val,im_val);%Have to construct it
case 3
ww1=10;ww2=10;wl1=10;wl2=25;
B=My_double_window(A,image_depth,tones,ww1,ww2,wl1,wl2);%Have to construct it
end
disp(round(B));
%======================================================
function [C]=My_plot(A,tones);
x=size(A,1);y=size(A,2);
for i=1:x
for j=1:y
ival=A(i,j);
tone_ival=(tones-1)*(double(ival)-0)/(31-0);
C(i,j)=tone_ival;
end;
end;
disp(round(C));
%========================================================
function [C]=My_simple_window(A,image_depth,tones,WW,WL);
% WL=window level
% WW=window level
x=size(A,1);y=size(A,2);
We=(2.0*WL+WW)/2.0;
if(We>image_depth) We=image_depth;end;
Ws=We-WW;
if(Ws<0) Ws=0;end;
for i=1:x,
for j=1:y,
ival=A(i,j);
if (ival<=Ws) tone_ival=0; end;
if (ival>=We) tone_ival=tones-1;end;
if ( ival>=Ws & ival<=We)
tone_ival=(tones-1)*(double(ival)-Ws)/(We-Ws);
end;
C(i,j)=tone_ival;
end;
end;
0 comentarios
Respuestas (1)
Walter Roberson
el 10 de Mzo. de 2011
You would put everything you show in to a file named Program_1.m . Save the file and then at the command prompt type
Program_1;
You will not be able to get back any results unless you change your line,
function []=Program_1
so that it has at least one variable name in the [] part, such as
function [B]=Program_1
If you do that, then at the command line you could type, e.g.,
MyB = Program_1;
This would save the (numeric) output to the variable MyB
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!