How to add a column of cell arrays o a table according to data
2 次查看(过去 30 天)
显示 更早的评论
I need to report in the column Var4 of the table SimultedPoints the values of column Discharge of table Name_Code. All of the values of the table Name_Code are present in the table SimulatedPoints. I need to fill the cell arrays of Var4 with the Discahrge values if the Names and Codes matches in the two tables and with zeros if they don't.
E.g
in Var4{idxPoint=1} I should obtain a vector of length 148x1 filled with zeros but a discharge data in correspondence of the position of 7.8675e+04 in the cellarray SimulatedPoints.Codes{idxPoint}
for i=length(Name_Code)
idxPoint=find(Name_Code.Name(i)==SimulatedPoints.Name(:))
length_vector=SimulatedPoints.Codes{idxPoint,:};
n=length(SimulatedPoints.Discharge{idxPoint});
for j=1:length(length_vector)
if length_vector(j)==Name_Code.Codes{i,:}
k(j)=Name_Code.Discharge{i}(j,1);
SimulatedPoints.Var4{idxPoint}=k(j);
else
SimulatedPoints.Var4{idxPoint}k(j);
k(j)=0;
end
end
end
1 个评论
Yazan
2021-8-15
Upload your data to make it easier for people to understand your problem, hence provide help.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!