Effacer les filtres
Effacer les filtres

Simple For loop through a Column

29 vues (au cours des 30 derniers jours)
Matt Brianik
Matt Brianik le 13 Jan 2018
Commenté : Matt Brianik le 15 Jan 2018
I Have a for loop that iterates through a data table and based on certain criteria it will replace or keep the value found. The issue I have is that it only works for the fist column and does not affect the remaining columns. I put an example of my code below. The result should be a 3x4 table with the first columns being 1000, 101000, 1000. and then should repeat in the other 3 columns. How do i get it to iterate through correctly?
NumRows=3
MDL= [0.5;0.5;0.5]
x=(1:4)
y=(101:104)
TABLE=[x;y;x]
g=1;
Collum=1;
k=1;
RowTurnedTable=TABLE(:,Collum)
for i=1:NumRows;
if RowTurnedTable(i) < MDL(i)
TABLE(i)=MDL(i)*10
else TABLE(i) = TABLE(i)*1000
end
end

Réponse acceptée

Image Analyst
Image Analyst le 13 Jan 2018
Your loop loops over rows, not columns. Try this:
numRows=3;
MDL= [0.5;0.5;0.5]
x=(1:4);
y=(101:104);
TABLE=[x;y;x]
g=1;
column=1;
k=1;
RowTurnedTable=TABLE(:, column) % Not sure what this is for.
for row = 1 : numRows
if RowTurnedTable(row) < MDL(row)
TABLE(row, :)=MDL(row)*10; % Never happens!
else
TABLE(row, :) = TABLE(row, :)*1000;
end
end
TABLE
  1 commentaire
Matt Brianik
Matt Brianik le 15 Jan 2018
Thank you,
This helped

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by