# Help with output values.

5 visualizzazioni (ultimi 30 giorni)
Johan Raniseth il 28 Apr 2015
Commentato: Johan Raniseth il 29 Apr 2015
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

pfb il 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.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Johan Raniseth il 29 Apr 2015
Thank you very much. I'll take a look :)

Accedi per commentare.

### Categorie

Scopri di più su Programming in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by