How to run multiple iterations while increasing the index?

I'm new to Matlab and I am trying to create a for loop.
I am trying to run the second line on each index in the array of imdata. How can I write a for loop where the index continuously increases but saves each result into a csv/table?
Below is what I have so far. Thank you for your help!
imdata(2).perforder
[N, edges] = histcounts(x)

 Accepted Answer

Rik
Rik on 24 Aug 2020
Edited: Rik on 24 Aug 2020
The easiest way to do this is to standardize the bins. If you don't want that, you should probably use a cell array.
for n=1:numel(imdata)
x=imdata(n).perforder;
[N{n}, edges{n}] = histcounts(x);
end

2 Comments

Thank you! I just figured that part out, but I am still having trouble putting the 'N' strings into a csv file. Do you know how to do that?
It isn't a string, it is a vector. What format would you like to have? Just the numbers with a comma in between?

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 24 Aug 2020

Commented:

Rik
on 24 Aug 2020

Community Treasure Hunt

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

Start Hunting!