How to write numbers before it occurs?

1 view (last 30 days)
Hey,
i have a problem that i am trying to solve for some time but still haven't. I have a matrix with 6 columns and a lot of rows. In example i put just 3 columns:
AA =
0.001 4.55 0
0.002 4.68 0
0.003 4.59 0
0,005 4.78 0
0,006 4.99 5
....
So what i need is to find the number (it can vary from 1 to 7) and take this number and write the same number up the cells until it reaches 3000 cell from that number. Than take another one and do the same and etc. So it this exaple i would get:
AA=
0.001 4.55 5
0.002 4.68 5
0.003 4.59 5
0,005 4.78 5
0,006 4.99 5
....
Could anyone lead me on the right track how to do it? I would appreciate any kind of help.
  2 Comments
Walter Roberson
Walter Roberson on 15 Oct 2019
AA(startrow-2999:startrow, appropriate_column) = number_to_write;
Ingrida
Ingrida on 15 Oct 2019
Walter, thank you for your answer. This would help, but i don't know the row numbers. I was thinking maybe i should find the right number from column 6 and then find the row where it stands and then use your answer above?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Oct 2019
rowidx = find(AAA(:,appropriate_column) ~= 0);
for start_row = rowidx(:).' %need to be sure it is a row vector
AA(startrow-3000:startrow-1, appropriate_column) = AAA(start_row, appropriate_column);
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!