How to assign to an empty array
이전 댓글 표시
Hi How to check in a column of table whether every row is assigned or not. If not how can I add a new value. I have assigned till 4. Now I want to assign 5 to the empty unassigned space.
i have two tables.
item rad ID
1 22 1
1 24 2
1 25 3
1 32 4
item rad ID
2 22.5 1
2 24.7 2
2 25.5 3
2 32.6 4
2 34
i want to assign ID for 34 as 5... if theres any other empty cell in table 2 then 6, 7 and so on. how can i use it inside a for loop so if theres any empty field, it inserts number after the last value assigned
댓글 수: 2
Rik
2019년 8월 2일
I would expect you can use the isempty function. Can you provide example input and output?
karishma koshy
2019년 8월 2일
답변 (1개)
madhan ravi
2019년 8월 2일
편집: madhan ravi
2019년 8월 2일
It's always better that you provide the data as Rik mentioned:
column = 1;
idx = cellfun('isempty',table2cell(T(:,column))); % T your table
T{idx,column} = {5}
edit:
So you have two tables say T1 and T2:
column = 3;
T = [T1;T2]; % concatenate them as one
idx = cellfun('isempty',table2cell(T(:,column))); % find the empty ones
STartwith = 5;
T{idx,column} =num2cell((1:nnz(idx)).' - 1 + STartwith)
댓글 수: 7
karishma koshy
2019년 8월 2일
madhan ravi
2019년 8월 2일
See edit in the answer.
karishma koshy
2019년 8월 2일
madhan ravi
2019년 8월 2일
My comment remains the same.
karishma koshy
2019년 8월 2일
편집: karishma koshy
2019년 8월 2일
madhan ravi
2019년 8월 2일
편집: madhan ravi
2019년 8월 2일
Not sure what you mean. Illustrate with an example and your desired output. And DON'T ever copy the output from a command window and paste it here (it's never useful) , always paste the code (that produces the table)!! Is there anyway of deducing it as one table instead of 100 such tables, in the first place?. The task would have been easier.
karishma koshy
2019년 8월 2일
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!