Q
矩陣值
0
A
回答
2
的clc
和disp
是最簡單的方法(由Tim爲應答)的組合,這裏就是你可能看中的,這取決於你一個「漂亮」的方法需要。這不會那麼快,但是您可能會發現一些好處,例如不必清除命令窗口或能夠對顏色進行編碼並保存無花果。
使用dispMatrixInFig
(代碼在這個答案的底部),您可以在每個階段的圖形窗口(或獨特的數字窗口)中查看矩陣。
實例測試代碼:
fig = figure;
% Loop 10 times, pausing for 1sec each loop, display matrix
for i=1:10
A = rand(5, 5);
dispMatrixInFig(A,fig)
pause(1)
end
輸出爲一個迭代:
評論功能代碼:
function dispMatrixInFig(A, fig, strstyle, figname)
%% Given a figure "fig" and a matrix "A", the matrix is displayed in the
% figure. If no figure is supplied then a new one is created.
%
% strstyle is optional to specify the string display of each value, for
% details see SPRINTF. Default is 4d.p. Can set to default by passing '' or
% no argument.
%
% figname will appear in the title bar of the figure.
if nargin < 2
fig = figure;
else
clf(fig);
end
if nargin < 3 || strcmp(strstyle, '')
strstyle = '%3.4f';
end
if nargin < 4
figname = '';
end
% Get size of matrix
[m,n] = size(A);
% Turn axes off, set origin to top left
axis off;
axis ij;
set(fig,'DefaultTextFontName','courier', ...
'DefaultTextHorizontalAlignment','left', ...
'DefaultTextVerticalAlignment','bottom', ...
'DefaultTextClipping','on');
fig.Name = figname;
axis([1, m-1, 1, n]);
drawnow
tmp = text(.5,.5,'t');
% height and width of character
ext = get(tmp, 'Extent');
dy = ext(4);
wch = ext(3);
dwc = 2*wch;
dx = 8*wch + dwc;
% set matrix values to fig positions
x = 1;
for i = 1:n
y = 0.5 + dy/2;
for j = 1:m
y = y + 1;
text(x,y,sprintf(strstyle,A(j,i)));
end
x = x + dx;
end
% Tidy up display
axis([1-dwc/2 1+n*dx-dwc/2 1 m+1]);
set(gca, 'YTick', [], 'XTickLabel',[],'Visible','on');
set(gca,'XTick',(1-dwc/2):dx:x);
set(gca,'XGrid','on','GridLineStyle','-');
end
2
我還以爲你可以用disp
實現這一目標:
for i=1:10
A = rand(5, 5);
disp(A);
end
如果你的意思是你不希望在控制檯彼此頂部反覆輸出,可以包括clc
清除各disp
呼叫前控制檯:
for i=1:10
A = rand(5, 5);
clc;
disp(A);
end
0
如果你想上一個數字顯示您的矩陣這很容易。只需製作一個轉儲矩陣並顯示它。然後使用文本功能在圖上顯示您的矩陣。例如
randMatrix=rand(5);
figure,imagesc(ones(20));axis image;
hold on;text(2,10,num2str(randMatrix))
如果你想要做一個for循環和看到數字的變化,試試這個:
for i=1:100;
randMatrix=rand(5);
figure(1),clf
imagesc(ones(20));axis image;
hold on;text(2,10,num2str(randMatrix));
drawnow;
end
+0
很短,您需要在'num2str'內爲字符串添加一些格式(https://uk.mathworks.com/help/matlab/ref/num2str.html#btf97wr),以便每列的寬度相同,並且如此一致。 – Wolfie
相關問題
- 1. 反轉矩陣值
- 2. 缺失值矩陣
- 3. R-用矩陣的平均值替換矩陣中的值?
- 4. 更改矩陣中的值
- 5. Opencv矩陣值顯示
- 6. 矩陣中的INDEX MATCH值
- 7. PHP設置矩陣值爲
- 8. 二維矩陣值差
- 9. 獲取矩陣的值
- 10. 選擇R矩陣值
- 11. 更改矩陣中的值
- 12. SSRS多價值矩陣場
- 13. matlab條件矩陣賦值
- 14. 移位矩陣中的值
- 15. jQuery矩陣輸入值
- 16. 矩陣:得到正值
- 17. Matlab的:替換矩陣值
- 18. Python numpy矩陣賦值
- 19. 將值賦給2D矩陣
- 20. 在C++中插值矩陣
- 21. XML值的矩陣計算
- 22. 矩陣的Binning平均值
- 23. 大矩陣的SciPy插值
- 24. 閾值在矩陣matlab
- 25. RCPP矩陣二值化
- 26. 識別矩陣中的值
- 27. Lop不需要矩陣值?
- 28. 3D矩陣真值表
- 29. 矩陣插值算法
- 30. 轉換圖像值矩陣
尼斯一個...另一種方法可能是'openvar (「A」)',其顯示能夠順利通過的任何變化自動更新以'A' ...,看一下[linkdata](https://www.mathworks.com/help/matlab/ref/linkdata陣列編輯器。 HTML)可能也很有趣,如果願意更新一些情節,而不是可視化的值 – CitizenInsane
我試圖操縱th e數組編輯器通過'v = desktop.getGroupContainer('Variables');'或'v = com.mathworks.mlservices.MLArrayEditorServices'命令編寫,但除了使數組版本只讀或不使用,這太難以取代變量的解除版本在它自己的身影通過命令 – CitizenInsane
@CitizenInsane,我在剛剛開放的變量運行一對夫婦的快速測試,但它似乎並不可靠地更新每次迭代。 – Wolfie