Getting output as an array from while loop

7 visualizaciones (últimos 30 días)
MAzharul Islam
MAzharul Islam el 18 de Mayo de 2020
Comentada: MAzharul Islam el 19 de Mayo de 2020
clc
clear all
a=0;
x = input('Enter the number : ')
while x<100
%%example code
if rem(x,2)==0
x=x+2;
else
x=x+1;
end
a=a+1;
format long
b=[a x]
end
c=[1 20; 2 22; 3 24]
I want the output of b as a 2 dimensional array where all the values a and x will be existed as like c.

Respuesta aceptada

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 18 de Mayo de 2020
Here is one of the viable solutions:
a=0;
x = input('Enter the number : ')
ii=0;
while x<100
ii=ii+1;
if rem(x,2)==0
x=x+2;
else
x=x+1;
end
a=a+1;
format long
b(ii,:)=[a x]
end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by