473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Data Structure in Matlab Constructor Function

Could someone please explain me the following Matlab code?
It has the constructor function to pass the data into the myClass variables (a,d,noInput) and the constructor has
the data structure (StructParameters). As I understand so far,
by using the data structure (StructParameters) the constructor function passes the data into the myClass variables.

- What is the purpose of using if-else condition with StructParameters.noInput? what is the meaning of that in this Matlab code?
- How can I access into the structured data, StructParameters?
- How can I run the following error condition? Any exaple commands for this?
***error('Input argument has to be struct.')

Many thanks in advance!!!

Expand|Select|Wrap|Line Numbers
  1. classdef myClass
  2. properties
  3.  a;
  4.  d;
  5.  noInput;
  6. end
  7.  
  8. methods
  9.  function obj=myClass(StructParameters)
  10.  if nargin==0
  11.  StructParameters.noInput=1;
  12.  else
  13.  StructParameters.noInput=0;
  14.  end
  15.  
  16.  if ~isstruct(StructParameters)
  17.  error('Input argument has to be struct.')
  18.  else
  19.  % load the parameters
  20.  F=fields(StructParameters);
  21.  for x=1:length(F)
  22.  obj.(F{x})=StructParameters.(F{x});
  23.  end
  24.  end
  25.  
  26.  if ~isfield(StructParameters, 'a')
  27.  obj.a=[1 2; 4 5];
  28.  end
  29.  
  30.  if ~isfield(StructParameters, 'd')
  31.  obj.d=[0 1; 4 5];
  32.  end
  33.  
  34.  end
  35.  
  36.  end
  37.  
  38. end
  39.  
Jun 18 '17 #1
0 1348

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jerrygarciuh | last post by:
Hello, I have a nice, simple mySQL abstraction layer I have worked out in PHP. Recently I realized on a project that I wanted one of my objects to automatically clean-up its table on creation. ...
3
by: John Phung | last post by:
How do you pass a data structure into a function? I'm using c++ to solve the producer and consumer problem and so far, I cannot find an example of how to do this. So, if anyone can help me, that...
7
by: Lynn | last post by:
I am rewriting some memory management code and I need to have a forward declaration of a data structure. I am not converting this data structure into a class (yet). How do I generate a forward...
2
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to...
1
by: dd | last post by:
Hi, I'm porting some matlab programs to C and wonder wether someone has tried to use C to realize some data structure like cells in Matlab? I used ***p to realize cells that are like k*m*n,...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
16
by: fuiwong | last post by:
Can i create a constructor in a data structure? does the following codes right? sample code #include <iostream.h> struct USERID{ char UserName; char Password; char LoginName; char...
4
by: aaragon | last post by:
Hi everyone, I am trying to create a class but I would like to be able to chose between several data structures for one of its members. The basic idea is template < class Sequence =...
0
by: MikeCS | last post by:
Hi all I would like some help with this issue. I am new to VB 2005 (OK with VB6) My problem is that I cannot seem to return a structure from a function. Example: I defined a structure in a...
4
by: Alexander Adam | last post by:
Hello folks, I got a few question on some basic data structure stuff. Sorry if those questions might sound too easy or such but after googling a lot I didn't find a real answer to all those...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.