My code runs in script and not in app design
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi I wrote a code in script and it works but when I copy the exact code in app design it give me the error:" Error using ./ Arrays have incompatible sizes for this operation. Help pls
3 Commenti
dpb
il 1 Lug 2024
You have a difference in how you're defining and/or passing the data to the function in the app as compared to how you're running it as a script.
In a script, everything is global in the command window; inside app designer the script has had to have been turned into a function and nothing outside the function is available to it...you must pass everything as an argument or create additional members of the app stuct that is global that you can reference inside the function.
But, we can't tell anything without at least the script/function and as a minimum, the app struct and the function from the app designer code; the startup code won't be of much import unless somebody here were to want to try to download and run it as well.
Rik
il 2 Lug 2024
One lesson here is that you shouldn't use scripts for actual work. Using functions provides a stable interface you can document, debug, and reuse.
Try to remake your code into a function. Once you do that, reuse is trivial. During the conversion you will find the source of the problem of your question.
Risposte (1)
Ishaan Mehta
il 23 Dic 2024
Hi Jawad,
The mentioed error in MATLAB occurs when you try to perform operations (such as subtraction) on two arrays that have different sizes or dimensions that are not compatible with each other, as discussed in the following documentation page:
Compatible Array Sizes for Basic Operations: https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html
To confirm the size of the arrays in use by your MATLAB App is compatible, a good first step would be to place a debugging breakpoint in MATLAB App Designer's "Code View" tab on the line throwing the error, and then verify the compatibility of your array variables. Once the breakpoint is hit and the execution stops, you can hover over the variables to check for the current value, or use the MATLAB Command Window to print them. Moreover, the "size" function will be helpful to check the size of the arrays.
Below documentation offers more information on how to use the built-in debugger in MATLAB.
Debug MATLAB Code Files: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html
Hope this helps.
0 Commenti
Vedere anche
Categorie
Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!