Help with output values.

1 回表示 (過去 30 日間)
Johan Raniseth
Johan Raniseth 2015 年 4 月 28 日
コメント済み: Johan Raniseth 2015 年 4 月 29 日
I have a function that I call but I would prefer the output I get to look more like a vector.
The code is a function calling on another function which computes a sequence of x-values.
function [] = MatOb()
x_values = MatOb1(2,2,50);
x = [x_values];
s = 'X values:'
disp(x)
end
function [x_values] = MatOb1(a, x, N)
x_values(1) = x;
for n = 2:N
x_values(n) = a*sin(x_values(n-1));
end
end
The output I get is on the form:
Columns 1 through 11
2.0000 1.8186 1.9389 1.8660 1.9135 1.8837 1.9029 1.8907 1.8985 1.8936 1.8967
Columns 12 through 22
1.8947 1.8960 1.8952 1.8957 1.8954 1.8956 1.8954 1.8955 1.8955 1.8955 1.8955
Is there a way to get the output in a way where it looks more like a vector,
x = [x1,x2,...,xN]? or x = [x1 x2 .... xN]
- Johan

採用された回答

pfb
pfb 2015 年 4 月 28 日
If I get it right your function MatOb just prints x_values in the standard output. I fail to see the need of introducing one further variable "x". Anyway, if this is just a matter of standard output, you can use fprintf instead of disp
fprintf('x = [%s]\n',sprintf('%1.3f ',x));
As I say, you can do this by using x_values in place of x.
Take a look at the documentation of fprintf and sprintf to get the hang of it.
  1 件のコメント
Johan Raniseth
Johan Raniseth 2015 年 4 月 29 日
Thank you very much. I'll take a look :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by