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 Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by