matlab

Update matrix, single column per row where row index is in vecor

末鹿安然 提交于 2021-02-10 19:40:01
问题 Is there a way to update different column in each row of matrix, where row indices are stored in vector. Example mx = zeros(10,10); cols = [2 3 5 4 6 8 9 1 2 3]'; for i = 1:size(mx,1) mx(i,cols(i)) = 1; end mx produces 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 The question is, whether I can do it without the for loop? 回答1: You can

MATLAB——矩阵排序详解

强颜欢笑 提交于 2021-02-10 18:40:47
<span style="font-size:18px;">(1)B=sort(A) 对一维或二维数组进行升序排序,并返回排序后的数组,当A为二维时,对数组每一列进行排序. eg: A=[1,5,3],则sort(A)=[1,3,5] A=[1,5,3;2,4,1],则sort(A)=[1,4,1;2,5,3] (2)B=sort(A,dim),对数组按指定方向进行升序排序, dim =1,表示对每一列进行排序,,dim=2表示对每一行进行排序. (3)B=sort(A,dim,mode),mode为指定排序模式,mode为"ascend"时,进行升序排序,为"descend "时,进行降序排序. (4)[B,I]=sort(A,.....),I为返回的排序后元素在原数组中的行位置或列位置. 一些例子: >> A=[3 4 2;1 5 3;4 7 1] A = 3 4 2 1 5 3 4 7 1 >> A(:) ans = 3 1 4 4 5 7 2 3 1 >> min(A(:)) ans = 1 >> max(A(:)) ans = 7 >> A A = 3 4 2 1 5 3 4 7 1 >> sort(A) ans = 1 4 1 3 5 2 4 7 3 >> A A = 3 4 2 1 5 3 4 7 1 >> sort(A(:)) ans = 1 1 2 3 3 4 4

Matlab : Study of the commutator with 2 Fisher matrices

孤街醉人 提交于 2021-02-10 18:20:24
问题 In Matlab, I have to study the eventual existence of common eigenvectors basis between 2 Fisher matrices FISH_sp and FISH_xc of size 7x7 and diagonalisable. I get from my computation the following result: >> x=null(FISH_sp*FISH_xc-FISH_xc*FISH_sp) x = -0.0085 -0.0048 -0.2098 0.9776 -0.0089 -0.0026 0.0109 In this result, It appears that condition to get a common eigenvectors basis on commutator is true. But I need to further examine the mathematics. If one gets a single column vector, then

Matlab : Study of the commutator with 2 Fisher matrices

爷,独闯天下 提交于 2021-02-10 18:19:06
问题 In Matlab, I have to study the eventual existence of common eigenvectors basis between 2 Fisher matrices FISH_sp and FISH_xc of size 7x7 and diagonalisable. I get from my computation the following result: >> x=null(FISH_sp*FISH_xc-FISH_xc*FISH_sp) x = -0.0085 -0.0048 -0.2098 0.9776 -0.0089 -0.0026 0.0109 In this result, It appears that condition to get a common eigenvectors basis on commutator is true. But I need to further examine the mathematics. If one gets a single column vector, then

Fourth-order Runge–Kutta method (RK4) collapses after a few iterations

微笑、不失礼 提交于 2021-02-10 18:02:10
问题 I'm trying to solve: x' = 60*x - 0.2*x*y; y' = 0.01*x*y - 100* y; using the fourth-order Runge-Kutta algorithm. Starting points: x(0) = 8000, y(0) = 300 range: [0,15] Here's the complete function: function [xx yy time r] = rk4_m(x,y,step) A = 0; B = 15; h = step; iteration=0; t = tic; xh2 = x; yh2 = y; rr = zeros(floor(15/step)-1,1); xx = zeros(floor(15/step)-1,1); yy = zeros(floor(15/step)-1,1); AA = zeros(1, floor(15/step)-1); while( A < B) A = A+h; iteration = iteration + 1; xx(iteration)

Moving Filter/Mask Across Given Image (No Function)

这一生的挚爱 提交于 2021-02-10 17:55:38
问题 I am struggling attempting to create a program that pads an image and filter/mask. Where I am having trouble is actually attempting to move this filter over each bit of the image without using a function to do so. Here is what I have so far. L=256; %Gray Levels %Saving Dimensions of both Filter and Image Sizes [FilterX , FilterY] = size(Filter); [ImageX , ImageY]= size(Image); % Padding Image pad1 = FilterY; PAD = (pad1-1); %New Padded Image With Zeros MaskX = ImageX + PAD; MaskY = ImageY +

matlab考试重点详解

给你一囗甜甜゛ 提交于 2021-02-10 17:47:32
  此帖是根据期末考试复习重点补充完成, 由于使用word编辑引用图片和链接略有不便, 所以开此贴供复习及学习使用。侵删 复习要点 第一章 Matlab的基本概念,名称的来源,基本功能,帮助的使用方法 1.基本概念和名称来源: MATLAB [1] 是美国 MathWorks 公司出品的商业 数学软件 , 用于算法开发、数据可视化、数据分析以及 数值计算 的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink两大部分。 MATLAB是matrix&laboratory两个词的 组合 ,意为矩阵工厂(矩阵实验室) 2.基本功能:   2.1数值计算和符号计算功能   MATLAB以矩阵作为数据操作的基本单位,还提供了十分丰富的数值计算函数。   2.2绘图功能,matlab提供了两个层次的绘图操作。一种是对图形句柄,进行底层绘图操作。另一种是建立在低层绘图操作之上的高层绘图操作。   2.3编程语言   MATLAB具有程序结构控制、函数调用、数据结构、输入输出、面向对象等程序语言特征,而且简单易学、编程效率高   2.4MATLAB工具箱   MATLAB包含两部分内容:基本部分和各种可选的工具箱。   MATLAB工具箱分为两大类:功能性工具箱和学科性工具箱。 3.帮助的使用方法   3.1 帮助命令   MATLAB帮助命令包括help命令和lookfor命令。

Ideal Low Pass Filter Concept in MATLAB

…衆ロ難τιáo~ 提交于 2021-02-10 16:22:43
问题 Please help me understand the following MATLAB code for Ideal Low pass filter. I am unable to understand the Part2 in the below code. Please explain me why we are doing like this. I have read the Rafael C. Gonzalez's Digital Image Processing Using Matlab 2E which explains my question but I couldn't understand properly. It will be helpful if someone could explain me clearly. Note: Dogbert, my understanding is that applying transform to an image help to separate low and high frequency

how to load Matlab's struct (saved with v7.3) in Python

谁都会走 提交于 2021-02-10 14:19:35
问题 I created a 1X20 struct in Matlab. This struct has 9 fields. The struct is saved in -v7.3 version because of its dimensions (about 3 Giga). one of the fields contains 4D matrix, other contain cell arrays, meaning it is a complex struct. I would like to know if there is a way to load this struct into Python? 回答1: MATLAB v7.3 uses HDF5 storage; scipy.io.loadmat cannot handle that MATLAB: Differences between .mat versions Instead you have to use numpy plus h5py How to read a v7.3 mat file via

Equality results when using a matrix of strings

被刻印的时光 ゝ 提交于 2021-02-10 12:56:54
问题 I don't understand why using == to compare between a string vector and a matrix of strings and the vector is of dimension n , I obtain a matrix of size n * n . I expected it to be of size n only, with a 1 when the string is equal. octave:13> t = ["aha";"bgb";"ctc"] t = aha bgb ctc octave:14> t == "aha" warning: mx_el_eq: automatic broadcasting operation applied ans = 1 1 1 0 0 0 0 0 0 What's going on underneath to explain such result ? And is it possible to do away with the warning: warning: