# How to Create Structure within a Function

2 views (last 30 days)
jrz on 23 Oct 2022
Commented: jrz on 23 Oct 2022
I have a function that calculates a number of values, for simplicity, lets call them x,y,z. I want to create a structure within the function that saves these values for use in other functions. How can this be done?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Can Atalay on 23 Oct 2022
You mean like this?
function [structure_youre_trying_to_create] = function_youre_using(input_1,input_2)
x = input_1+input_2
y = input_1*input_2
z = x*y
structure_youre_trying_to_create = struct();
structure_youre_trying_to_create.addition = x;
structure_youre_trying_to_create.multiply = y;
structure_youre_trying_to_create.combine = z;
end
##### 1 CommentShowHide None
jrz on 23 Oct 2022
Exacty like that, thanks so much!

Sign in to comment.

### Categories

Find more on Structures in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!