Why is my assigned variable not being detected/read?

조회 수: 15 (최근 30일)
shnrndll
shnrndll 2019년 6월 27일
댓글: Jan 2019년 7월 2일
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
Adam
Adam 2019년 7월 2일
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 2019년 7월 2일
@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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2019년 6월 28일
편집: Jan 2019년 6월 28일
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
Stephen23
Stephen23 2019년 7월 1일
편집: Stephen23 2019년 7월 1일
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 2019년 7월 2일
@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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by