I'm trying to write a program that types out a line with n integers starting with n0 , separated by commas and spaces. It needs to use a forloop and should turn out like this n=10 n0=5 --> 5, 6, 7, 8, 9, 10, 11, 12, 13, 14. This is what I have so far

조회 수: 1 (최근 30일)
%Countem
%Program that types out a line with n integers starting with n0
%Author Dmitri
clear;clc
%% set parameters
n=10
%% calculate
for n0=5:n
f(n0)=n0
end
%% Display results
  댓글 수: 3
Custode Dmitri Francesco
Custode Dmitri Francesco 2019년 10월 20일
This needs to be done with a loop and it is fine to leave them hard-coded.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2019년 10월 20일
Since this is a homework assignment, I will leave some blanks for you to fill in.
n=10;n0=5;
clc%clear command window
for k=n0+(___ vector with n elements, starting at 1 ___)-1
fprintf(_____,k);%look up fprintf in the documentation to see how it works
end
If you need a more explicit hint for the definition of k, feel free to post a comment.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by