Writing data to table with for loops
이전 댓글 표시
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
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
2019년 6월 11일
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;
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!