How can I assign counter defined data in an array in MATLAB GUIDE - ex. data_array​(counter)=​some_data

1 visualización (últimos 30 días)
Dear MATLAB Community Members,
This is my first time posting on MATLAB Answers, so if I had omitted something or done wrong, please, forgive me for that.
At the start I would like to Thank You - in advance, for trying and hopefully helping me to solve this problem. I strongly believe, that this problem will be interesting to many future MATLAB GUI beginners, as I am myself one of them. I am using MATLAB R2017b version.
This GUI should work like this: You enter data into the edit box (one by one), press plus - push button, the GUI counts that button press, increments the counter by 1, and after that works like: some_array(counter)=data; , I would like to store my data in an array because latter I can do whatever I like with it. For the: counter=1, some_data_array(1)=10; for counter=2, some_data_array(2)=20; for counter=3, some_data_array(3)=30; etc... data info are only as example. I need, a row vector, or column - never mind... just as it is a 1D vector. Info: I do not know how many entries there can be - it's up to the user, so no finite upper number for loop (for) code structures. As well, the counting is displayed in Static text box just for testing display, there will be the sum of the array, or some other data related info into static box... Please, this is the main question here - and number 1) priority.
1) How to enter data in a row/column vector using counter as it's element position definer (in vector) using MATLAB GUI? That data/vector will be used, later, between others callbacks/functions in the GUI.
It would be better if it is possible to solve this without loops... BUT, any suggestion and any solution are more than welcome!
Motive's and background: I started learning MATLAB GUI (now with GUIDE, will do later with App developer...) circa 7 days ago. After I had successfully completed few basic examples which included some graphing and/or basic operations and engineering formula - after few hours, I have stuck to this problem for the last six or seven days... , due to not being able to assign an counter position defined value to an array in GUI. I am pretty much frustrated at the moment for not being able to finding the way to assign a value to AN ARRAY IN GUI USING COUNTER... which is an almost basic thing to do in MATLAB - ex. repetition structures (for loop, while, etc...). I have scrolled/read many answers in MATLAB Answers, Stack overflow, internet in general, etc... the answers were nowhere to find...
Here is the whole code presented. The .fig and .m files are in attachments, and in .txt file it is presented the output from MATLAB command line, after running - executing, this program (GUI). This is just for pure practicing and learning MATLAB GUIDE and MATLAB GUI capabilities - in general, by my side.
For me, and possibly for some other future MATLAB GUI users will be very useful the answer to this problem. I am interested - in general in the solution of this problem, of course and in this code presented here - hopefully, if someone has some time to spare... I meant to say: I am working on one broader problem (GUI). And, I have segmented the problem - related to coding, in segments. And, this is one of the segments. The most problematic one - to be honest.
As well, part 2) of this question, is: How to implement the upper mentioned in a 2D matrix ( m x n ), or whatever matrix/array dimension (with multiple pages)? How the main question labeled 1), can be done for higher order matrices, starting from 2D, 3D, etc... the general principle... and/or code hopefully.
The reason I need an array, is because when I have it, I can do whatever I need with it, and later will find the: sum(some_data_array), and use some other statistical properties on data. All the data is entered trough the same Edit Box - this is important to minimalize the GUI. As well, as a bonus question 3) : How You save/export that created array (some_data_array) to .dat file or .m file (from the 'basis' workspace...)? Asking this, because the data or analysis, can be used by other related applications...
Sincerely, Thank You.
EDIT: Have removed the code from the body of question - as suggested, and have attached the .fig file and .mat file for easier testing.
REM: Download and use the .m file and .fig file found in attachment for testing Your, potential, solution code. If it works - in that way, the answer will be accepted.
Short command window preview after counter=4 :
handles =
struct with fields:
figure1: [1×1 Figure]
text2: [1×1 UIControl]
edit1: [1×1 UIControl]
pushbutton1: [1×1 UIControl]
output: [1×1 Figure]
input1: 40
data_edit1 =
40
C =
40
br =
4
intermediary_array =
0 0 0 40
>>
  8 comentarios
Teodo
Teodo el 22 de Feb. de 2018
Editada: Teodo el 22 de Feb. de 2018
@ Jan Simon: Ok. Thank You - very much, for helping in clarification of possible causes for “disappearing” few posts. It can be a possible unintentional SQL injection during correcting/updating posts with some odd and wrong/strange combination of bold * * or italic _ _ formating... maybe... I don’t know... , yes, it’s possible … or an empty field data commit... Maybe.
And, Thank You for the code provided to some other OP/topic – for on button push/click counter code in GUIDE GUI. I am using it -with credits, in the upper attached .m file and it works great.
@ Stephen Cobeldick: Ok. Thank You - sincerely, for all the time and effort invested in trying to help me to solve this problem. I really appreciate it.
BTW, I am now switching from GUIDE to MATLAB App Developer. Hopefully it is more flexible, even thought GUIDE is a great application - with some drawbacks...
Teodo
Teodo el 23 de Feb. de 2018
Editada: Teodo el 23 de Feb. de 2018
As an info/update/curiosity:
Tried tonight the same thing in App Designer, and I get identical (!) results/problem, as in GUIDE - related with the problem here presented/described. Still getting an array with counter defined elements, but it has all zeros, and only on last element/place - in that moment, you get the latest entry. I couldn’t believe my eyes when I saw it in command window. :-)
Again, I cannot understand why this has to be so difficult… to create an array, counter defined... in MATLAB’s GUIDE/AppDesigner…
If someone solves this, it would be really, really a useful thing for both MATLAB graphic developers - GUIDE and App Designer.
Note: Will attach here in this post the .mlapp file so who ever likes/wishes can test it, and see that it is behaving exactly like his GUIDE GUI counterpart. Although, producing/making a GUI in MATLAB App Designer is at least 100 times easier (!) and user friendly than in GUIDE. Compliments to MathWorks on that!
REM: Download/unzip and use the .mlapp file found in attachment in this post for testing Your, potential, solution code. If it works - in that way, the answer will be accepted.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Dialog Boxes en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by