Resize cell array to match size of second cell array
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Marcel
am 18 Nov. 2022
1 Kommentar
Jan
am 19 Nov. 2022
A simplification:
function [In, Out] = fixArraySize(In, Out, fillData)
% I've removed "app", which is not used here.
nIn = size(In, 2);
nOut = size(Out, 2);
if isempty(In)
In = Out;
elseif nOut < nIn % array 1 is smaller
% No loop needed. Should it be nOut+1:nIn ?
Out(1, nOut:nIn) = {fillData};
elseif nOut > nIn % array 1 is bigger
Out(nIn+1:nOut) = [];
end
end
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!