Azzera filtri
Azzera filtri

How to make a loop

3 visualizzazioni (ultimi 30 giorni)
Lev Mihailov
Lev Mihailov il 27 Ago 2019
Commentato: KALYAN ACHARJYA il 27 Ago 2019
Hello! I have a loop and I cannot configure it correctly
x=(0:1:100);
n=length(x);
for i=1:10
y=data(:,i); % data matrix 100000x10
end
with this format, the matrix considers all the values ​​for me, but I only need those that fall in length n
for i=1:n
y=data(101,i); % data matrix 100000x10
end
my task is to count the required number of lines, but I just can’t get such an option
  2 Commenti
Rik
Rik il 27 Ago 2019
What do you mean? You really need to make your question as clear as possible: describe your input and describe the required output. Also be aware that using length is a bad habit. You should either use numel or the size(A,dim) syntax.
Shubham Gupta
Shubham Gupta il 27 Ago 2019
but I only need those that fall in length n
You want nth row element of each column
y = data(n,:);
or you want nth row element of specific column
specific_column = 2;
y = data(n,specific_column);
Or you want element from each column with a gap equal to n
y = data(n:n:end,:);
Not really sure what you want to achieve but I hope above code helps you out !

Accedi per commentare.

Risposta accettata

KALYAN ACHARJYA
KALYAN ACHARJYA il 27 Ago 2019
Modificato: KALYAN ACHARJYA il 27 Ago 2019
"with this format, the matrix considers all the values ​​for me, but I only need those that fall in length n"
x=(0:1:100);
n=input('Enter the required Length');
for i=1:n
y(i)=x(i);
end
y
Without Loop:
x=(0:1:100);
n=input('Enter the required Length');
y=x(1:n)
*Please note that n must be same or smaller than actual x length.
  2 Commenti
Rik
Rik il 27 Ago 2019
This misses the point that the data is actually a matrix, so this probably isn't the solution.
KALYAN ACHARJYA
KALYAN ACHARJYA il 27 Ago 2019
May be, but If we consider the data, then there is no role of x
n=input('Enter the required Length');
y=data(1:n)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by