Info
This question is closed. Reopen it to edit or answer.
GUI error : Subscripted assignment dimension mismatch.
3 views (last 30 days)
Show older comments
n = [1 2 3 4];
for i= 1:4
h = n(i) ;
Ca1 = x(1:4);
Cb1 = x(5:8);
Ca2 = x(9:12);
Cb2 = x(13:16);
fun (i) = 1/tiempo*(Cao - Ca1(i)) - (k*Ca1(i)).^h;
fun (i+4) = -1/tiempo*Cb1(i) + (k*Ca1(i)).^h;
fun(i+8) = 1/tiempo*(Ca1(i) - Ca2(i)) - (k*Ca2(i)).^h;
fun (i+12) = 1/tiempo*(Cb1(i) - Cb2(i)) - (k*Ca2(i)).^h;
end
This are the functions I use in order to solve a problem. (This goes in a different script)
When I run my GUI the message: Subscripted assignment dimension mismatch. And the error appears to be the functions (fun) in my other script. Just to clarify, this is an EDO problem and in my code in the GUI I did this:
[t,x] = ode45 (@Proy, tint, xo); (example)
The name of my other scrip is "Proy".
3 Comments
Jan
on 12 Nov 2017
Writing in UPPERCASE means shouting in the forum. Therefore let me ask you to calm down. Thanks.
Answers (1)
Jan
on 12 Nov 2017
Edited: Jan
on 12 Nov 2017
ERROR NOW IS THE FOLLOWING: SWITCH EXPRESSION MUST BE A SCALAR
OR A CHARACTER VECTOR
Again: Please post the complete error message, not just a part of it. It is really inefficient to let the readers guess the details.
Obviously "Proy" is not a script, but a function. This is an important difference.
tiempo = eval(get(handles.residencia,'String'));
eval is an ugly command. There are always better methods. I assume you want sscanf. Note what happens, if a funny user types this in your edit field:
'system(''format D:'')'
Then your eval will destroy the data on the disk D. What a bad idea.
Using global variables is a source of bugs and unexpected side effects. Provide parameters by anonymous functions: http://www.mathworks.com/matlabcentral/answers/1971
The cause of the error is:
preg = contenido(q);
Then preg is a scalar cell string, but as the error message tells you, you need a string:
preg = contenido{q}; % Curly braces
A simplification:
if tiempo <= 10
tint = [0,100];
elseif tiempo <= 45
tint = [0,250];
else
tint = [0,450];
end
[t,x] = ode45 (@Proy, tint, xo);
Avoid duplicate code in programs to reduce the number of lines, which have to be debugged or changed in case of modifications.
3 Comments
Jan
on 13 Nov 2017
@Daniels Frias: You need help and I am glad, when I can help you. Please do not treat me, like I am super intelligent or all-knowing. Even if you are new at programming GUIs you know much more about your code and the problem, then I do. I do not have the faintest idea and cannot know anything, which you do not provide. I (and all other readers of your question) need clear explanation about what your are doing and the complete error message. If I have to ask twice for it, I get the impression that you do not want to make it as easy as possible to help you. You still did not tell us, which line is causing the "Subscripted assignment dimension mismatch" error or if this problem is solved now.
As far as I can see, Walter has formatted your code in the question now. Thanks, Walter!
The frequent contributors in this forum inform newcomers multiple times each day to format the code properly. Asking for the error messages is daily routine also, as well as remembering what UPPERCASE means in all forums. We warn several times each day, when eval or globals are used, see e.g. https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. The differences between scripts and functions are explained repeatedly also.
Asking questions for clarifications and providing suggestions for improving the code is not meant personally. All I want to do is helping you to solve your problem, but this should not be made harder then necessary.
Is the problem with the code solved now?
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!