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

  • Context: MATLAB 
  • Thread starter Thread starter darthxepher
  • Start date Start date
  • Tags Tags
    Field Structure
Click For Summary
SUMMARY

The forum discussion centers on troubleshooting the passing of string inputs in MATLAB's structure field function. The user encounters an error when attempting to access a non-existent field 'fname' in a structure array. The provided code snippet demonstrates the issue, specifically in the line [m n] = size(Q(1).fname). The discussion highlights the need for proper field referencing in MATLAB structures to avoid such errors.

PREREQUISITES
  • Understanding of MATLAB structure arrays
  • Familiarity with MATLAB function syntax
  • Knowledge of error handling in MATLAB
  • Basic debugging techniques in MATLAB
NEXT STEPS
  • Review MATLAB documentation on structure arrays
  • Learn about dynamic field referencing in MATLAB
  • Explore error handling techniques in MATLAB functions
  • Investigate best practices for function parameter passing in MATLAB
USEFUL FOR

MATLAB users, software developers, and data analysts who are working with structure arrays and need to troubleshoot field access issues in their code.

darthxepher
Messages
56
Reaction score
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
Does no one really know?
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
7
Views
9K
  • · Replies 14 ·
Replies
14
Views
7K