insert zero into the column in the array
Ältere Kommentare anzeigen
Hi,
I have a array of size 49 x 3 (Attached here), here, I would like to make entries in the thrird column starts from 1 to 100. Next, for each missed entries in the third column, i need to insert zero in the second column. Please let men know how to do this ..
Akzeptierte Antwort
Weitere Antworten (1)
Turbulence Analysis
am 5 Feb. 2022
0 Stimmen
1 Kommentar
Sure. Make those few lines of code into a function and then call the function on each cell using cellfun().
(I modified the code to keep the values in the first column the same as what they were in the original matrix, rather than setting them all to 2, since they vary in the matrices in this cell array.)
load('matlab.mat');
new_Data = cellfun(@fill_to_100,Data,'UniformOutput',false);
disp(Data{1});
disp(new_Data{1});
disp(Data{end});
disp(new_Data{end});
function new_A = fill_to_100(A)
new_A = zeros(100,3);
new_A(:,1) = A(1,1);
new_A(:,3) = 1:100;
[ism,idx] = ismember(1:100,A(:,3));
new_A(ism,2) = A(idx(ism),2);
end
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!