How to print array value and it's undex?

I have an array of single column data, array length of about ~8000 members.
I want to print some data interval from array, so id array is named 'data', I use a single line
data(6500:end)
and this outputs a list of elements starting of element#6500 to the end of array.
How I can print element index along with it's value?
F.e. initially I have output:
100
105
103
120
.......
and I want to see something like :
6500 100
6501 105
6502 103
6503 120
......................

 Accepted Answer

It would be necessary to print the indices as well —
data(6500:6503,:) = [100
105
103
120];
idx_data = [(6500:6503).' data(6500:6503)]
idx_data = 4×2
6500 100 6501 105 6502 103 6503 120
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fprintf(1,'%d %.0f\n', [(6500:6503).' data(6500:6503)].')
6500 100 6501 105 6502 103 6503 120
Since you already know the indices you want to print, this should be straightforward.
.

More Answers (0)

Products

Release

R2024b

Tags

Community Treasure Hunt

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

Start Hunting!