Resize cell array to match size of second cell array
Show older comments
Hi i have two cell arrays like the following where im using a camera for measuring temperature. Wire, Body and Lense are dynamically added, depending if the camera operatior descides to measure theses spots on the cam or not.
The problem is, as in this examle, im getting a error: "Dimeonsions of arrays are being concatenated or not consistend.". I can see why, tho im not really sure how to fix this, and so far a simple application restart did the job just right, tho thats not a nice fix.
If seen something with cellfun/arrayfun but im not sure on how to do it.
TL;DR
the size of these two arrays can change at any time, and when this happens, i need the smaller one to have the same size as the bigger one, filling the new added values to match the new size with something like 0 or "UPDATED".
newColumn =
1×6 cell array
{'Date'} {'Time'} {'IP Address'} {'Wire'} {'Body'} {'Lense'}
newData =
1×5 string array
"1970-01-01←" "02:36:17.304←" "10.x.x.x←" "35" "43"
Im error occurs here:
% oldData = a 21x5 array
oldData = [app.UITable.Data]
newData = rowData
updatedData = [newData;oldData];
% Verkleinert die Größe des Arrays damit sich das Programm
% nicht aufhängt oder zu langsam wird.
maxEntries = app.AnzahlmaxEintrgeinAppListeEditField.Value;
if size(updatedData, 1) > maxEntries
updatedData = updatedData(1:maxEntries, 1:size(updatedData, 2));
end
app.UITable.Data = updatedData;
10 Comments
Jan
on 16 Nov 2022
Which array is concerned? Where do which error message occur? Please post a copy of the complete message.
Marcel
on 16 Nov 2022
The problem is likely due to the values being dynamically added, per your description. This relinquishes control of where the values are added within the array. If the order of the values within the two arrays matter, then you must enter those values using indexing rather than entering them dynamically.
Example:
people = ["John","Abby","Ralf","Jane"];
scores = [100, 80, 20];
There is a missing score but we have no idea whose score is missing.
Assuming the "people" variable in my example is the independent variable, meaning that you control that, then the "scores" array is the dependent variable and should be preallocated to the same size as the independent variable. Then, indexing should be used to assign values to scores depending on whose data the scores belong to.
people = ["John","Abby","Ralf","Jane"];
scores = nan(size(people))
% Enter score for "Jane"
scores(strcmp(people, "Jane")) = 20
% Enter scores for the rest of the people,
% except the person with missing data
scores(strcmp(people, "Abby")) = 80
scores(strcmp(people, "John")) = 100
Now all of the scores as in the same order as people and we see that Ralf is missing a score.
Marcel
on 17 Nov 2022
Adam Danz
on 17 Nov 2022
Did you figure out how to remove the unused cells? Sounds like you solved this :)
Marcel
on 17 Nov 2022
Adam Danz
on 17 Nov 2022
Are the empty or missing values causing a problem or is the issue that they just don't look nice?
Marcel
on 18 Nov 2022
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!