Troubleshooting: Passing String Inputs in Matlab's Structure Field Function

In summary, a structure field in Matlab is a data structure that allows for hierarchical organization and storage of data. It is created using the "struct" function and can be accessed and modified using dot notation. Nested structure fields are also possible, and a structure field can be converted into a matrix using the "struct2array" or "struct2table" functions.
  • #1
darthxepher
56
0
For some reason, when I try to use this function it has a problem passing along the fname input.
For example, I'd type something like :

Field(S, 'names')

------------------------------

This returns an error:

? Reference to non-existent field 'fname'.

Error in ==> CheckFieldConsistency at 4
[m n] = size(Q(1).fname);

---------------------------------


function output = Field(Q, fname)

k = 0;
[m n] = size(Q(1).fname);
dim = [m n];


Can someone please enlighten me on how I would go about passing this string along into the function to be utilized?

Thank you for your time.
 
Physics news on Phys.org
  • #2
Does no one really know?
 

What is a structure field in Matlab?

A structure field in Matlab is a data structure that allows you to organize and store data in a hierarchical format. It is similar to a cell array, but it has named fields that make it easier to access and manipulate data.

How do I create a structure field in Matlab?

To create a structure field in Matlab, you can use the "struct" function. For example, you can create a structure with two fields, "name" and "age", by using the command "myStruct = struct('name', 'John', 'age', 30);".

How can I access and modify data in a structure field?

You can access data in a structure field by using the dot notation, for example, "myStruct.name" would return the value of the "name" field in the structure "myStruct". You can modify data in a structure field by assigning a new value to the field, for example, "myStruct.name = 'Jane';" would change the value of the "name" field to "Jane".

Can I have nested structure fields in Matlab?

Yes, you can have nested structure fields in Matlab. This means that a field in a structure can itself be a structure, allowing you to create a hierarchy of data. You can access nested fields by using multiple dot notations, for example, "myStruct.field1.field2" would access the "field2" field in the structure "field1" in the structure "myStruct".

How can I convert a structure field into a matrix in Matlab?

You can convert a structure field into a matrix in Matlab by using the "struct2array" function. This function converts the values of a specified field in a structure into a matrix. You can also use the "struct2table" function to convert a structure field into a table, which can then be converted into a matrix using the "table2array" function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
5K
  • Programming and Computer Science
Replies
5
Views
881
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
5K
Back
Top