필터 지우기
필터 지우기

How to write a function that run specific sections of the script

조회 수: 3 (최근 30일)
Matheus  Pacifici
Matheus Pacifici 2019년 10월 9일
편집: John Doe 2019년 10월 9일
I have functional script that can output a table in 3 different ways.
I want the user to be able to choose which format of the table he wants.
I have a script with 3 different sections, so I'm trying to get the user to choose which section he wants to run with a function.
I tried: function [ table] = data_analysis (dataset)
if dataset= 1
....
elseif dataset = 2
....
else
...
end
end
But MatLab doen's accept if statements that define the input.
Any ideas on how to do this?
Thanks

답변 (1개)

John Doe
John Doe 2019년 10월 9일
편집: John Doe 2019년 10월 9일
You need to use == as opposed to = ;
function [a] = data_analysis(x)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if x == 1
a = 1;
elseif x == 2
a = 2;
elseif x == 3
a = 3;
else
fprintf('Please specifiy and input between 1 and 3')
end
end
I would also suggest using a better name for your function than data_analysis.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by