How can I assign counter defined data in an array in MATLAB GUIDE - ex. data_array(counter)=some_data
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Dialog Boxes in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!