How to call a function in an m file in a function in another m file in MATLAB

3 ビュー (過去 30 日間)
Syed
Syed 2013 年 9 月 7 日
Hi,
I have two functions in separate m files in the same directory given as:
1st function:
function [P] = Calculate_Transmission_Prob_Matrix()
% this function calculates a transmission probability matrix (i.e., P)
2nd function:
% this function calculates stationary_probability by combining the transmission probability matrix (P) and a matrix of ones which is of the same size as P.
function stationary_probability = Calculate_Stationary_Probability()
Here's how i called the 1st function in the second function:
[P] = Calculate_Transmission_Prob_Matrix();
stationary_probability_initialize = ones(size(P));
stationary_probability = [stationary_probability_initialize P];
Is this correct? If not how can i correct it?

採用された回答

Image Analyst
Image Analyst 2013 年 9 月 7 日
編集済み: Image Analyst 2013 年 9 月 7 日
Looks correct, other than you don't need the enclosing brackets in [P] in either the function definition or when you call it. You only need them when there are more than 1 return variables. Also, stationary_probability_initialize and P must have the same number of rows for you to stitch them together side by side, but your ones() function will handle that fine.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by