0

I want to for-loop through some values and for each value of the index I want to save an image to the disk. Is there a way to achieve the following:

N = 16;
name_RGB = ["RGBN" N ".jpeg"];

imwrite(image1, name_RGB, "jpeg");

??

So to explain, the loop is currently on index 16. I want to save an image with the name "RGBN16.jpeg". Anyone know if it is possible to join strings and variables together in Octave?

2

1 Answer 1

3

You just need to convert the numeric value to a string, then you can concatenate, like this:

N = 16;
name_RGB = ["RGBN" num2str(N) ".jpeg"];

imwrite(image1, name_RGB, "jpeg");

For more options, see the documentation here:

https://www.gnu.org/software/octave/doc/v4.0.1/Converting-Numerical-Data-to-Strings.html

Sign up to request clarification or add additional context in comments.

3 Comments

Literally just got it as you submitted the answer!!! Thanks for your troubles all the same :)
I would use something like fn=sprintf ("RGBN%i.jpeg", N);
@whatwhatwhat: Please consider accepting this as answer if it answers your question even if you found the answer yourself just before you read gariepys answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.