Help with output values.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!