Resize cell array to match size of second cell array
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Marcel
2022 年 11 月 18 日
1 件のコメント
Jan
2022 年 11 月 19 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!