How to create a vector to store my values

Hello all,
I have this for loop shown below which prints for every Iteration what you can see right in the following picture. What I wanna do and dont know how, is to take all these Routes for every Iteration and store it in a vector [1 x m ], so that in the end of the execution the final vector would have all those routes inside. Could anyone help me by providing me that extra line of code in my already existing code? Probabbly all that it needs is to add 1 more loop outside that one but I dont know how to form it correctly.
Thank you very much
my code:
the results:
To make my answer more accurate, I need a vector which according to the shown result would be something like
p = [ 1 5 9 10 2 22 23 1 14 4 11 24 15 1 13 21 12 3 7 1 8 6 19 26 1 20 16 25 17 1]
Thanks in advance!

1 Comment

per isakson
per isakson on 20 Dec 2020
Edited: per isakson on 20 Dec 2020
"provide me with a code line that could generate the vector" More than one line is required.
Your chance to get a detailed answer increases if you provide your code as text and format it with . Select the text and click the button.

Sign in to comment.

Answers (1)

In you incorporate indexing into your assignment statement, you can tell MATLAB where to store each result. See the example "Assign Matrix Values" on the for-loop documentation page.

2 Comments

You just need some more experience with indexing. I'd suggest Ch 5 and Ch 13 of MATLAB Onramp.
John Smith's "Answer" moved here:
I have tried a couple of things in the process of making a way to solve my problem, but unfortunatelly it seems that none of them worked in the end.. My coding skills might be still poor for such a task, so if anyone could provide me with a code line that could generate the vector Ι need (that would store inside all the generating routes), Ι'd be really grateful.

Sign in to comment.

Categories

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

Products

Release

R2015b

Asked:

on 18 Dec 2020

Edited:

on 20 Dec 2020

Community Treasure Hunt

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

Start Hunting!