Why is my assigned variable not being detected/read?
16 ビュー (過去 30 日間)
古いコメントを表示
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
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
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
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
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
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 Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!