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

 採用された回答

Oleg Komarov
Oleg Komarov 2011 年 7 月 2 日

0 投票

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 件のコメント

Jared Singleton
Jared Singleton 2011 年 7 月 2 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by