Matrix 处理
将所有非零的元素变为1,为零的元素保持为0,使用
~~
, 可用于二值化1
A=~~A;
Get indices of elements in upper triangle
1
2nNodes = size(adj,1); % get the number of nodes in a matrix
upperInds = find(triu(ones(nNodes),1));Sort the node strength and plot matrix by sorting results
1
2
3stg = strengths_und(A)';
[srtVals srtInds] = sort(stg);
imagesc(log10(A(srtInds, srtInds)));Set infinite values to 0:
1
A(isinf(A))=0;
Compute Euclidean distance and convert to matrix
···
D = pdist(X); % calculate the distance between pairs in X
M = squareform(D) % convert to the symmetry matrix
···
画图
设置图像背景,位置:
1
hf=figure; hf.Position=[100,350,600,300]; hf.Color='w';
设置坐标轴用
gca
1
2
3
4
5ax = gca; % current axes
ax.FontSize = 12;
ax.XTick = [0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1];
ax.XTickLabel = [0.02 0.02];
ax.XLim = [-2 2];去掉坐标轴,按像素实际大小画图
1
axis off; axis equal;
Scatter plot matrix: diagonal are replaced with histogram plots of the data in the corresponding column of X. Off-diagonal parts are scatter plots of the columns of X against other columns of X.
1
2X = randn(50,3);
plotmatrix(X)
Read and write file
Read nii file
1
[hdr,data]=read(filename)
Write to a txt file
1
2dlmwrite('coords.txt',coords,'delimiter',' ');
dlmwrite('matrix.txt',A,'delimiter',' ');Combine data into a table with column headers
1
2att = array2table([ci stg degree clust], 'VariableNames', {'module','strength','degree','clustering'});
writetable(att, 'attributes.txt','delimiter',' ');
Others
在命令行窗口输出
1
fprintf('Subject: %0.3f\n',some_value);
Get the running time of code
1
2
3tic
code here
tocdiff
function: to calculate the incremental change between each pair of values in an array.linspace
function: creates a vector of n equally spaced elements between any two values, x1 and x2.x = linspace(x1,x2,n)