How to create this table
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

The table above is an example i get it from teacher.
How to do table like this? I didnt have any concept for doing table like this....... My question is if customer is odd number the output will show out at the counter 1 and if even number the output will show out at the counter 2
0 comentarios
Respuestas (1)
NVSL
el 25 de Abr. de 2025
Hi @Daniel Chew
As I can see, the image you provided doesn’t imply your statement of counter division based on parity.
The division based on parity can be done by filling the opposite counter values with NaN. The below code, with comments explains the workflow in more detail.
% An example data (10 rows, 3 columns)
data = reshape(1:30, 10, 3); % Example: 1-30 arranged as 10x3 matrix
% Taking parity as Counter trade-off
odd_idx = 1:2:size(data,1);
even_idx = 2:2:size(data,1);
% Create tables for odd and even indexed rows
table1 = array2table(data(odd_idx,:), 'VariableNames', {'A1','A2','A3'});
table2 = array2table(data(even_idx,:), 'VariableNames', {'B1','B2','B3'});
% Prepare final table columns, initialize with NaN
nRows = size(data,1);
Index = (1:nRows)'; % Index column
A1 = nan(nRows,1); % Odd data columns
A2 = nan(nRows,1);
A3 = nan(nRows,1);
B1 = nan(nRows,1); % Even data columns
B2 = nan(nRows,1);
B3 = nan(nRows,1);
% Populate odd rows with data from table1
A1(odd_idx) = table1.A1;
A2(odd_idx) = table1.A2;
A3(odd_idx) = table1.A3;
% Populate even rows with data from table2
B1(even_idx) = table2.B1;
B2(even_idx) = table2.B2;
B3(even_idx) = table2.B3;
% Merge all the columns to a table
resultTable = table(Index, A1, A2, A3, B1, B2, B3);
%Display
disp(resultTable);
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!