How to assign to an empty array

21 views (last 30 days)
karishma koshy
karishma koshy on 2 Aug 2019
Commented: karishma koshy on 2 Aug 2019
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 Comments
Rik
Rik on 2 Aug 2019
I would expect you can use the isempty function. Can you provide example input and output?
karishma koshy
karishma koshy on 2 Aug 2019
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

Sign in to comment.

Answers (1)

madhan ravi
madhan ravi on 2 Aug 2019
Edited: madhan ravi on 2 Aug 2019
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 Comments
madhan ravi
madhan ravi on 2 Aug 2019
Edited: madhan ravi on 2 Aug 2019
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
karishma koshy on 2 Aug 2019
% make arrays into tables
data1 = array2table(row_frame1_data,'VariableNames',{'frame','centre_x','centre_y','radius'});
data2 = array2table(row_frame2_data,'VariableNames',{'frame','centre_x','centre_y','radius'});
% assign id's to data2
data2.id = (1:size(data2,1))';
% find row numbers in frame1 data that have matching rows in frame2 data
% (these are the rows of result1 that have a 1 in them)
iRow = find(any(result1,2));
% find row numbers in frame 2 where each match occurs
[id,~] = find(result1');
% assign these ids in data1
% rows that don't have a matching ID will be assigned NaN
data1.id = NaN(size(data1,1),1);
data1.id(iRow) = id;
% display results
disp(data1)
disp(data2)
i want a for loop of the same. inside the for loop i want to assign the ID to data1. Then i want to find the assigned point in frame i. if no assigned point, i want to assign as next available ID. If assigned point, I want to set ID for i+1 equal to ID for i. result1 is a logical array
Expected Output
frame centrex centrey ID
1 2 3 1
1 7 9 2
2 3 3 1
2 8 10 2
3 5 20 3
3 8 9 2
so on

Sign in to comment.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!