Loop to edit cell values

1 回表示 (過去 30 日間)
kathy
kathy 2019 年 11 月 26 日
コメント済み: Ridwan Alam 2019 年 11 月 28 日
Hello,
I have a 99312x2 table.
Column 1 has values in increments of 60 (i.e. 0,60,120,etc) representing hours/minutes. I need to change these to days, such that all cells in column 1 that have values of 0-1440 are changed to value 1, then the cells that have values of 1500-2880 are all changed to values of 2.
I was trying to think through a for-loop that would find the first pair of cells that have a difference of 1440 (number of minutes in a day) and change all the cells between those two cells (and including those two to 1), then loop back to find the next pair and change those cells to value of 2, and so on. But I'm not very good with loops.
Something along the lines of:
for i = 0:99312
%not sure how to set the x value
if x-i==1440
%all the cells between x and i are changed to 1 through about 1655
end
Goal:
ExampleOfNewCells.png

採用された回答

Ridwan Alam
Ridwan Alam 2019 年 11 月 26 日
編集済み: Ridwan Alam 2019 年 11 月 26 日
Assuming your table is named 'myTable' with size 99312x2, you can get the new column from the first column directly by dividing the column and ceiling the decimal values.
newColumn = ceil(table2array(myTable(:,1))/1440);
  2 件のコメント
kathy
kathy 2019 年 11 月 27 日
Sweet! Thank you!
Ridwan Alam
Ridwan Alam 2019 年 11 月 28 日
Sure. Glad it helped.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by