My code runs in script and not in app design
조회 수: 4 (최근 30일)
이전 댓글 표시
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
dpb
2024년 7월 1일
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
2024년 7월 2일
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.
답변 (1개)
Ishaan Mehta
2024년 12월 23일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!