MATLAB: Writing data to table with for loops

for looptablewrite to table

I currently have the data displayed as a printed equation in the Command window, but I would rather have it set up in a table with individual variable names. I simplified the code to just the parts that would affect the table, but I'm not sure how to get it to actually print the values how I want. The variable names for the table would be Output (from spurs(m,n)), m_value, LO_value, n_value, and RF_value
for LO = 11:2:21
lo = [0 1 2 3 4 5].*LO
for RF = 2:0.1:18
rf = [1; 2; 3; 4; 5]*RF
rf = rf(:)
spurs = [(lo(1)-rf) (lo(2)-rf) (lo(3)-rf) (lo(4)-rf) (lo(5)-rf) lo(6)-rf]
for m = [1 2 3 4 5]
for n = [1 2 3 4 5 6]
if spurs(m,n) > 3 && spurs(m,n) < 5.1
Print = [num2str(spurs(m,n)), ' = ', num2str(m), '*', num2str(LO), '-', num2str(n), '*', num2str(RF)];
disp(Print)
end
end
end
end
end

Best Answer

As commented you don't need loops to construct all your spurs:
LO = 11:2:21;
RF = 2:0.1:18;
n = 0:5;
m = 1:5;
[mm, nn, rf, lo] = ndgrid(m, n, RF, LO);
spurs = nn .* lo - mm .* rf;
It's then trivial to create a table from that:
tokeep = spurs > 3 & spurs < 5.1
result = table(mm(tokeep), nn(tokeep), rf(tokeep), lo(tokeep), spurs(tokeep), 'VariableNames', {'m', 'n', 'RF', 'LO', 'spur'})
There is no point in splitting that table into several tables according to LO. It will only complicate further processing.