Help with output values.

조회 수: 2 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by