Why is my assigned variable not being detected/read?

8 views (last 30 days)
This is where the problem starts, when I feed the user selected file(app.FileSelected) into this function, the selected file string should be read and then identified with any of the cases shown above. Based on the respective case I expect an output of a N dimensional cell array read out into the command window. But instead it is saying that variable UserData is not assigned. But as you can see UserData is initially equated to the reading of the binary file and then based on the string case it is reshaped.....PLEASE HELP SEE E
  3 Comments
Adam
Adam on 2 Jul 2019
As per your flag, we don't delete questions that have answers and further comments that people have put time and effort into as there is potentially still something useful for others in those answers too.
You can edit your question to clarify it better if you wish, though leave the substance of it as is because the answers need to still make sense relative to the question.
Jan
Jan on 2 Jul 2019
@shnrndll: After somebody has posted an answer, we avoid removing a question, because then the time for answering would be wasted. Readers learn from questions and answers and it is the nature of questions, that they contain errors and unclear details.
So please leave the thread untouched (I see, the code is removed already...) and open a new one, if this helps you.

Sign in to comment.

Accepted Answer

Jan
Jan on 28 Jun 2019
Edited: Jan on 28 Jun 2019
Your code creates app.UserData, but the error message tells you, that the output UserData is not created:
function UserData = ReadChkptFile(app, FileSelected, File_ID)
% ^^^^^^^^ ^^ ? ^^ ?
In addition the 2nd and 3rd input argument are marked in the editor, which means, that they are not used anywhere. You call this function like this:
% line 134
app.UserData = ReadChkptFiole(app, app.FileSelected, app.File_ID);
But most likely this would be sufficient already:
ReadChkptFiole(app);
because the variables for input and output are contained in the app already.
By the way, the expression fullfile(file) is exactly the same as file , so simply omit the fullfile() in the definition of app.FileSelected.
  4 Comments
Stephen23
Stephen23 on 1 Jul 2019
Edited: Stephen23 on 1 Jul 2019
You wrote the swtich inside an if , whose condition depends on the number of input arguments:
function ReadChkptFile(app, FileSelected, File_ID)
...
if nargin > 1
switch app.FileSelected
...
end
...
end
The switch never runs because you call that function once with one input argument:
ReadChkptFile(app);
Also note that 'A.*' is not a valid filename on Windows (and even if the other case conditions are valid filenames, without extensions they are unlikely to be the names of data files returned by uigetfile).
Jan
Jan on 2 Jul 2019
@shnrndll: Could you please stop posting code as screenshots? It is really hard to read them and using the contain information by copy&paste to post an answer is not working. Do not make it hard to type answers.
Of course Matlab stops at the breakpoint: this is the purpose of break-points. You have to step through the code line by line then. Please learn how to use the debugger: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
In the screenshot you can see, that the 2nd and 3rd input argument is marked. They have an orange background, to mention, that these variables are not used inside the function. Then omit them to decrease the clutter.
"my code is saving the user selected file {app.FileSelected} as an character array" - Of course: app.FileSelected is the name of the file. Storing this as char vector is the best idea.
Note: Using the curly braces in the text is confusing, because they mean a cell array in Matlab. Use the standard method to mark code by marking the term with the mouse and press the "M" in the title bar. So prefer app.FileSelected instead of writing {app.FileSelected}.
switch app.FileSelected
case 'A.*'
This compares the file name with the char vector 'A.*'. File names cannot contain a star under Windows (is this allowed under Linux?). Therefore it is not clear what you expect the code to do. A meaningful comment is recommended.
This command:
app.UserData = fread(app.File_ID,inf,'float32');
is performed for all cases. The call it once before the switch.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!