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

3 件のコメント

Jan
Jan 2019 年 6 月 11 日
How is "table" defined here? Do you mean a table object? Then what should be the contents? Currently you display char vectors only, but should the table contain numerical vectors or symbolic equations? Or do you mean an uitable object? Or a tabular display with automatic tab stops in the command window?
Please explain exactly, what you want to achieve.
Danielle Rivera
Danielle Rivera 2019 年 6 月 11 日
It would be a table object where for each spur(m,n) output in the set range, the spur(m,n) number, the m value, the n value, the RF value, and the LO value would be shown in the same row (columns for each of those variables) as numerical values not char/string values. Ideally I would have a table for each LO value, where the LO is still included in the table but a new table is made every time the LO value changes (6 tables instead of just 1).
Guillaume
Guillaume 2019 年 6 月 11 日
This line:
rf = rf(:)
does nothing since you've made sure to create a column vector in the previous line.
This line:
spurs = [(lo(1)-rf) (lo(2)-rf) (lo(3)-rf) (lo(4)-rf) (lo(5)-rf) lo(6)-rf]
is simply:
spurs = lo - rf; %if on R2016b or later
%spurs = bsxfun(@minus, lo, rf); %on earlier versions
Note that none of the loops are needed, you could just create a 4D matrix (m x n x RF x LO) in one go:
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;

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2019 年 6 月 11 日
編集済み: Guillaume 2019 年 6 月 11 日

2 投票

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.

3 件のコメント

Danielle Rivera
Danielle Rivera 2019 年 6 月 11 日
This is helpful, however I do need the for loop for the LO because I am plotting a new graph for every LO value after the spur table creation. Also, I think it would still be useful to break up the table by LO because it resulted in 1255 rows
Guillaume
Guillaume 2019 年 6 月 11 日
You probably don't need a loop for your plotting. It probably can be done all at once for each LO. For example to plot RF vs m for each LO:
figure; hold on;
rowfun(@(m, rf, lo) plot(m, rf, 'DisplayName', sprintf('LO = %d', lo(1))), result, 'GroupingVariables', 'LO', 'InputVariables', {'m', 'RF', 'LO'});
legend('show'); xlabel('m'); ylabel('RF');
it's probably not what you're plotting, so what are you plotting exactly?
I only get 631 rows but whatever the height why does it matter? Again, splitting it makes processing harder not easier.
Danielle Rivera
Danielle Rivera 2019 年 6 月 11 日
I'm making 3d stem plots with RF(x-axis), spurs(y-axis), and power(z-axis, values from a matrix). The table is intended to help with filter and mixer design and indicate isolation necessities and provide notice of undesired values that show up in the output range (3-5)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by