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

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 commentaires

Teodo
Teodo le 22 Fév 2018
Modifié(e) : Teodo le 22 Fév 2018
Who deleted half of the posts?! ...
You can either check in your followed pages (see your top bar, 'My MATLAB Answers' -> 'Activity Feed'), or in the global activity log (I checked back to 22 Feb 2018 at 5:48, you can check earlier dates yourself).
Teodo
Teodo le 22 Fév 2018
Modifié(e) : Teodo le 22 Fév 2018
Dear Rik,
on both the links/locations – where You addressed me to go, there is nothing – except this censored post. No previous conversations – it is deleted around 5-6 posts.
You can check all the posts, there was nothing that needed to be censored. As well, everything was argument backed - with facts (I have backed up last page and its content locally – on my HDD, and I can prove it).
I do not understand why there is censorship on a science topic - as the conversation/debate was civilized and supported with de-facto arguments?
Jan
Jan le 22 Fév 2018
Modifié(e) : Jan le 22 Fév 2018
@Teodo: I've checked the Recent Activity list again and do not find any deleting there. But in the cache of Google I find a comment of you from 21. Febr. 2018 23:00 GMT, which is not existing anymore now. This is strange!
Ask the admins by using the "Contact Us" button and ask for a clarification. The parts of the discussion I've found are clear, polite, on-topic and useful. I do not believe that somebody has "censored" them. Maybe a malfunction of the database?! I see some smart unicode quotes „ “ in the deleted comment, perhaps they trigger an SQL injection?!
Here the comment I've found in the cache - let's see if it vanishes "automatically" also:
Teodo wrote:
@ Stephen: Passing data between callbacks is not a problem, the GUI is doing it, and I figured out how to do it from the start, and even in other applications, before, that work/ed. The guidata yes transfers data between callbacks/functions, as it is doing with the counter variable, no problem with that. BUT, it seems that the dynamically addressed data ex. some_data(counter) is not, and I really don't know the reason why have integrated it couple of times on the right places but with no effect ( guidata(hObject, handles); - to update the handles changes). As well, it seems that guidata is working – of course, with structure handles (ex. handles.output, even: handles{1}.output structures) but it is not working on arrays... obviously. Or at least I do not know how to make them work.
„ You underestimate the complexity and requirements of asynchronous GUI interfaces. Loops are simple... and synchronous. GUIs are not. As you seem to be keen to learn it might help you to reduce the frustration level if you do some reading about asynchronous computing. “
Yes true, but it wasn't because of some negative drive, I just didn't know the story - You mentioned, about synchronous vs. Asynchronous in GUI interfaces ... Thank You for explaining/pointing out, will do some research on synchronous vs. asynchronous coding - preferably MATLAB related... And, yes, it helps a bit with the frustration :-) .
„ May I ask why you particularly want to use GUIDE? “
Yes, You may, of course: I do not like to leave things unfinished, in the first place. Then, I like to learn and understand what I don't know, or what I don't know enough... When I started learning GUIDE 7-8 days ago, I believed to push it to the limits for an average user - exploring/learning related... but it will not happen now... I will switch to MATLAB App Designer, for some time, if I don't encounter the same problem - naturally will try to build this same problem, then continue if all goes well.
„ I think you are overcomplicating this task (and the user interface) somewhat: if you want the user to input a table, then just use a uitable. “
Yes, I know that „table“ method - it can be done, BUT it is not the method: to make an input with one edit box, and ex. sum all the elements entered in the same edit box - with pressing one push button, and display the number of elements in ex. sum, and their sum - which is a more natural way of doing it for less experienced user (someone who will potentially use some app...generally speaking...), than entering values/data in a table, looking where and how to enter them, then interpreting the data by GUI, etc... I was insisting on this solution for the sheer reason of making it (GUI) on this particular way.
I do appreciate, a lot, Your help, time and effort. Thank You very much.
There is no censorship: I deleted my answer and my comments, as they turned out to be not relevant or useful for answering the question. Everything else here remains exactly as it was.
I notice that other regular users also remove their answers when they turn out to be irrelevant / incorrect / a misinterpretation of the question / ...
Teodo
Teodo le 22 Fév 2018
Modifié(e) : Teodo le 22 Fév 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 le 23 Fév 2018
Modifié(e) : Teodo le 23 Fév 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Question posée :

le 20 Fév 2018

Modifié(e) :

le 23 Fév 2018

Community Treasure Hunt

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

Start Hunting!

Translated by