Help with output values.
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
pfb
on 28 Apr 2015
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.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!