Fprintf and display in the same script

I have to display a series of numbers, fibonacci's through 15 using both fprintf and disp functions. I have managed to get it to work but not without work arounds. I need to know is there any way to execute the program without commenting out fprintf and flipping my variable, n. Code is below
clc; clear;
n = (0:15)';
f = (1/sqrt(5)).*((((1+sqrt(5))/2).^n)-(((1-sqrt(5))/2).^n));
%fprintf(1,'F%1.0f= %1.0f\n',[n;f]) %%to make this work, I have to get rid
%of the transpose on the n variable and comment out the disp command.
disp([repmat('F',16,1) num2str(n,'%1.0f') repmat('= ',16,1) num2str(f,'%1.0f') ]); %to get this to work, I have to add in the n variable and comment out the fprintf command

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 2 de Jul. de 2011
n = 0:15;
f = 1/sqrt(5).*(((1+sqrt(5))/2).^n-((1-sqrt(5))/2).^n);
sprintf('F%02.0f = %3.0f\n',[n;f])
disp( strcat('F', num2str(n.','%01.0f'), '=', num2str(f.','%3.0f')))

1 comentario

Jared Singleton
Jared Singleton el 2 de Jul. de 2011
thank you sir.. I should have thought of sprintf, but I was so focused on getting it the way the question asked.. I never thought about it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by