James Tursa's answer works perfectly to create arr4 as described above. But as a follow-up question, let's say one of my surveys returns as a type of arr3, but also includes data:
test_grid = {'apple','elephant1','elephant2';...
'0', '1', '1';...
'1', '1', '2'};
I'd then like to add this data to the larger array, arr4, and set all of the non-included values to 0, such that the final array would be:
final_grid =
3×12 cell array
'apple' 'berry' 'berry1' 'berry2' 'cat' 'cat1' 'cat2' 'cat3' 'dog' 'elephant' 'elephant1' 'elephant2'
'0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '1' '1'
'1' '0' '0' '0' '0' '0' '0' '0' '0' '0' '1' '2'
This is what I have so far, which I'm certain is about as inefficient as it gets:
%With the above arrays already declared, as well as test_grid and arr4:
[TOTAL_SAMPLES,~] = size(test_grid);
TOTAL_SAMPLES = TOTAL_SAMPLES - 1; %TOTAL_SAMPLES is the number of received data points
%It is also used elsewhere, which is why I'm leaving it as is and then adding 1 in the next line.
%Create final_grid as cell with titles and zeros
final_grid = cell(TOTAL_SAMPLES+1,length(arr4));
final_grid(1,:) = arr4;
[S,T] = size(final_grid);
for i = 2:S
for j = 1:T
final_grid(i,j) = {"0"};
end
end
%Fill in known columns with known values
for i = 1:length(test_grid)
[~,T] = find(strcmp(arr4,test_grid(1,i)));
final_grid(2:end,T) = test_grid(2:end,i);
end
I'm wondering if anyone knows of a more efficient way to acheive the overall tasks described. I find myself constantly writing for loops to handle my arrays which work, but in the back of my mind I feel like Matlab probably has other functions that could acheive my tasks with much more efficiency.