필터 지우기
필터 지우기

How can i make a function with a input parameter?

조회 수: 2 (최근 30일)
Philipp Mueller
Philipp Mueller 2016년 10월 12일
답변: Guillaume 2016년 10월 12일
Hi everybody,
This is my script code. I want to create a function with the input parameter 2.txt - file This function should create my plot. How can i do this? Thank you for your help.
clear all
clc
Input_Matrix_Woehler = textread('2.txt')
x1 = Input_Matrix_Woehler(:,1)
y1 = Input_Matrix_Woehler(:,2)
[xb,yb] = stairs(x1,y1);
figure1 = figure('Name','Woehler',...
'Color',[0.756862759590149 0.866666674613953 0.776470601558685]);
axes1 = axes('Parent',figure1);
hold(axes1,'on');
xlim(axes1,[1000 200000000]);
box(axes1,'on');
set(axes1,'Color',[0.894117653369904 0.941176474094391 0.901960790157318],...
'XMinorTick','on','XScale','log');
plot(yb,xb)
  댓글 수: 1
Preethi
Preethi 2016년 10월 12일
hi,
if you want to create a function, kindly check help/documentation once.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2016년 10월 12일
All you need to convert your script into a function is:
  • delete the clear all and clc. These have no place in a function
  • replace it with the function declaration, something like
function agoodnameforyourfunction(fullfilename)
%agoodnameforyourfunction Plots data from two column text file ...
%
%inputs:
% fullfilename: char array containing the full path of the text file
  • replace the hardcoded string in the textread call by the input variable name
Input_Matrix_Woehler = textread(fullfilename);
  • put an end at the end of the file.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by