Resize cell array to match size of second cell array
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marcel
el 16 de Nov. de 2022
Comentada: Jan
el 19 de Nov. de 2022
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 comentarios
Respuesta aceptada
Marcel
el 18 de Nov. de 2022
1 comentario
Jan
el 19 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!