Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Simple question about functions

Asked by JP

JP (view profile)

on 21 Jun 2013

Hello, just a simple question about functions. What I want to do is use a function in main code, and create a new variable from within a structure. My main code reads

 practicefcn()
 x=data1.x;

My function reads

 function [ data1,x ] = practicefcn()
 data1.x=5;
 data1.y=4;
 end

This gives me an error. Hopefully you see what I want to do. I want to create a datastructure where x = 5 within that data structure, but also I want to create a separate variable where x = 5, defined outside of the data structure. Thanks!

0 Comments

JP

JP (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 21 Jun 2013
Accepted answer
data1 = practicefcn();
x = data1.x;

0 Comments

Andrei Bobrov

Andrei Bobrov (view profile)

Contact us