- 博客(32)
- 收藏
- 关注
原创 matlab cody学习笔记 day23 判断输入的是否是向量
好久没更新了,今天刷一道(1)Problem 605. Whether the input is vector?Given the input x, return 1 if x is vector or else 0.我本来想的是获取X 的长度(length),如果是1的话,就不是向量,不知道为什么总是报错。答:y=isvector(x);最后只需要简单的一个函数就可以。。...
2021-03-23 10:46:56
1520
原创 matlab GUI学习笔记6 如何更改窗口标题,以及设置edit/text输入框的默认值
写了好久的本子,老师又给软件提了些要求,需要进行修改。(1)更改窗口标题为了方便窗口编程,每个窗口的名称都设置的很明了,例如下图这样,这个窗口对应的就是主窗口的pushbutton1,但作为软件成品来讲就很不讲究,所以需要对此进行修改。方法一:右键在fig的空白处点击一下,打开属性检查器,Name修改成你想设置的窗口名称,注意NumberTitle要改为OFF。修改完成后点击保存就可以了。方法二:在OpeningFcn程序里面添加语句:set(gcf,'NumberTitle
2021-03-19 10:16:07
8361
3
原创 matlab 小tips 如何保存大的矩阵文件
今天为了提高程序运行速度,把中间值的矩阵打算存成文件,save的时候报错了,原因是要保存的矩阵超过了2G。。解决方法很简单,就是在save语句的最后添加一个'-v7.3'就成功了。 save('filename.mat',' A','-v7.3'); 其中,filename.mat是要保存成的文件名,A是要保存的数据。...
2021-03-18 16:53:12
2057
原创 matlab cody学习笔记 day22 计算阻尼正弦曲线
感觉还是把题号写好比较好,万一有人想参考,搜题号的时候就可以搜到吧。(1)Problem 44948. Calculate a Damped SinusoidThe equation of a damped sinusoid can be written asy = A.ⅇ^(-λt)*cos(2πft)whereA,λ, andfare scalars andtis a vector.Calculate the output sinusoidygiven the inp...
2021-03-11 09:14:47
1013
原创 matlab cody学习笔记 day21
GUI编程的任务暂时告一段落,现在又要开始每天刷一道题目的日子了。(1)Problem 13. Remove all the consonantsRemove all the consonants in the given phrase.Example:Input s1 = 'Jack and Jill went up the hill';Output s2 is 'a a i e u e i';要想去掉所有的辅音,就要构建一个包含所有辅音的数组,然后逐一进行判断。答:fun
2021-03-10 09:44:52
220
原创 matlab GUI学习笔记5 如何导出exe文件,以及避免出现DOS黑屏
经过一周的艰苦奋斗,终于把老师要求的小程序给做完了,检查之后发现没什么问题就要开始导出.exe文件了,下面将一一记录我的学习和纠错过程。首先,关于版本,一开始的matlab版本是2017a,后来因为插件的原因改为2020b了。第一步,验证是否安装了转换exe文件的插件,检测命令为:’mbuild -setup’,如果出现如下错误,那么就要从安装插件开始了。第二步,安装插件,点击主页的“附加功能”,在下拉菜单里选择“获取硬件支持包”。打开的过程中,有可能会出现matl...
2021-03-09 19:56:04
1132
原创 matlab GUI学习笔记4 如何添加并设置下拉菜单以及GUI解决不用直接用load的问题
(1)输入“guide”新建一个GUI界面,在界面的左侧选择“弹出式菜单”添加到面板上(2)选择需要编辑的下拉菜单,右键选择或双击打开“属性检查器”,在String中编辑下拉菜单内容。(3)要实现下拉菜单的功能,需要对callback进行编辑,下拉菜单的tag一般默认为popupmenu1。但是需要注意的是,若点击pushbutton后需获取选择的内容,那么要把这段内容添加在pushbutton的callback里。vall = get(handles.popupmenu1,...
2021-03-08 19:29:26
7124
原创 matlab GUI学习笔记3 如何添加axes并刷新计算结果,以及初始化axes的句柄。
从昨天开始matlab GUI的编程需要用到图像显示了,也就是axes插件,里面涉及到很多问题,一一记录下来解决方法。(1)首先添加axes,很简单。图像显示框的名称叫坐标轴,很容易误会。(2)在axes中显示结果,即若点击计算按钮,在图像框中显示计算结果。计算按钮的tag为pushbutton1,在其callback中获取输入参数,并进行计算,将得到的计算图像显示,用“axes(handles.axes1); plot(t*1e6*1e6,d);%匹配结果"语句,或直接使用“plot(
2021-03-06 12:13:22
10949
2
原创 matlab GUI学习笔记2 如何关闭窗口和打开新的窗口 如何计算输入的数据
今天主要是三个内容:(1)如何关闭窗口;(2)打开新的窗口;(3)如何计算输入的数据,并显示结果(1)设置一个pushbutton为退出键,在该pushbutton的callback里添加语句“close(gcf);”即可。(2)要想打开一个新的窗口首先要新建一个窗口,并与原窗口放在同一个目录下,例如原窗口为“software.fig”,新建两个窗口为“pushbutton1.fig”和“pushbutton2.fig”,并放在同一目录下:当点击原窗口的pushbutton1时,弹出pu
2021-03-05 10:20:06
9884
1
原创 matlab GUI学习笔记1 如何生成一个GUI文件,及如何修改保存后的.fig文件
最近需要做一个项目的小软件,学习如何用matlab GUI生成一个小软件,带对话框等等。所以这几天对matlab GUI的分步学习进行记录。我的matlab版本是R2017a。首先是如何在matlab中生成一个GUI文件。(1)在命令行窗口输入“guide”命令并执行;(2)弹出一个对话框,选择第一个“Blank GUI(Default)”,点击“确定”;(3)之后就生成了一个空白的界面,需要将左侧的配件添加到界面中;(4)例如,添加一个按钮,选中图标点击右键,选择“属性检查
2021-03-04 11:11:25
6400
1
原创 matlab cody学习笔记 day20
终于上20天了,今天刷一道题目,之后打算把matlab GUI编程给记录一下,所以我之后这几天暂时不刷cody了。(1)Cell joinerYou are given a cell array of strings and a string delimiter. You need to produce one string which is composed of each string from the cell array separated by the delimiter.For ex
2021-03-04 08:51:18
479
1
原创 matlab cody学习笔记 day19
三月的第三天,眼睛疼(1)Nearest NumbersGiven a row vector of numbers, find the indices of the two nearest numbers.Examples:[index1 index2] = nearestNumbers([2 5 3 10 0 -3.1])index1 =1index2 =3[index1 index2] = nearestNumbers([-40 14 22 17])i
2021-03-03 09:51:59
315
原创 matlab cody学习笔记 day18
啊啊啊啊,陷入不想学习中无法自拔!(1)Verify Law of Large NumbersIf a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a
2021-03-02 10:18:38
327
原创 matlab cody学习笔记 day17
三月的第一天从熬夜开始的,哭唧唧。(1)Target sortingSort the given list of numbersaaccording to how far away each element is from the target valuet. The result should return the list sorted in descending order of the absolute value of the difference betweena(n)and...
2021-03-01 10:50:47
136
原创 matlab cody学习笔记 day16
这道题目如果要理逻辑其实还挺麻烦的,所以打算好好理理这道题目(1)Find the longest sequence of 1's in a binary sequence.Given a string such ass = '011110010000000100010111'find the length of the longest string of consecutive 1's. In this example, the answer would be 4.Example:
2021-02-28 16:27:23
232
1
原创 matlab cody学习笔记 day15
今天有点其他的任务,刚好刷到一道简简单单的题目,就只做这道题目了(1)Getting the indices from a vectorThis is a basic MATLAB operation. It is for instructional purposes.---You may already know how tofind the logical indicesof the elements of a vector that meet your criteria.Thi..
2021-02-27 10:45:00
157
原创 matlab cody学习笔记 day14
之后打算每天只刷一道题目了,毕竟题目现在越来越不容易了,除了了解matlab函数适应matlab编程外,我还想把一些复杂题目的逻辑理清楚。(1)求两个向量的内积今天的第一道题目比较简单,可以用dot函数,也可以直接相乘,直接相乘的时候注意矩阵转置,这两种方法的时间复杂度是一样的。答:function z = your_fcn_name(x,y)z = dot(x,y);答:function z = your_fcn_name(x,y)z = x*y‘;(2)第二题也很简单
2021-02-26 08:34:18
263
原创 matlab cody学习笔记 day13
感觉现在的题目越来越难了,好想每日鸡汤激励一下自己好好学习,不要怕!(1)Which values occur exactly three times?Return a list of all values (sorted smallest to largest) that appear exactly three times in the input vector x. So ifx = [1 2 5 2 2 7 8 3 3 1 3 8 8 8]theny = [2 3]一些函数的学习:C
2021-02-25 09:12:16
298
原创 matlab cody学习笔记 day12
(1)The Goldbach ConjectureThe Goldbach conjecture asserts that every even integer greater than 2 can be expressed as the sum of two primes.Given the even integer n, return primes p1 and p2 that satisfy the condition n = p1 + p2. Note that the primes are
2021-02-24 09:02:50
341
原创 matlab cody学习笔记 day11
想到要开学,要离开家,哭了一晚上,我想我妈妈!(1)Problem 30. Sort a list of complex numbers based on far they are from the origin.Given a list of complex numbers z, return a list zSorted such that the numbers that are farthest from the origin (0+0i) appear first.So if z is
2021-02-23 17:07:19
242
原创 matlab cody学习笔记 day10
(1)Check if number exists in vectorReturn 1 if number a exists in vector b otherwise return 0.a = 3;b = [1,2,4];Returns 0.a = 3;b = [1,2,3];Returns 1.这道题目还是很简单的,第一眼就觉得用find函数,但是还需要加判断。答:if true(find(b == a))y = 1elsey = 0end答:y = ~isempty(b
2021-02-20 22:11:24
130
原创 matlab cody学习笔记 day9
(1)Summing digitsGiven n, find the sum of the digits that make up 2^n.Example:Input n = 7Output b = 11since 2^7 = 128, and 1 + 2 + 8 = 11..答:function b = sumDigits(n)pow = 2^n;b = 0;while pow~=0b = b +mod(pow,10);pow = floor(pow/.
2021-02-19 16:39:24
202
原创 matlab cody学习笔记 day8
(1)Back and Forth RowsGiven a number n, create an n-by-n matrix in which the integers from 1 to n^2 wind back and forth along the rows as shown in the examples below.Examples:Input n = 3Output a = [ 1 2 36 5 47 8 9 ]Input n = 4Output a =
2021-02-15 12:00:33
192
原创 matlab cody学习笔记 day7
(1)Problem 25. Remove any row in which a NaN appearsGiven the matrix A, return B in which all the rows that have one or more NaNs have been removed. So forA = [ 1 5 8-3 NaN 140 6 NaN ];thenB = [ 1 5 8 ]答:function B = remove_nan_rows(A)
2021-01-29 16:58:13
391
2
原创 matlab cody学习笔记 day6 isempty和intersect函数的用法
一些学习心得:(1)圆柱表面积:圆柱的表面积=侧面积+两个底面积=2πrh+2πr^2(2)华氏度与摄氏度的转换:C = (F–32) * 5/9;(3)寻找完美的平方Given a vector of numbers, return true if one of the numbers is a square of one of the other numbers. Otherwise return false.Example:Input a = [2 3 4]Output b is
2021-01-17 10:57:07
630
原创 matlab cody学习笔记 day5
一些学习笔记:(1)数组的简单赋值:例如:Input n = 5Output m is [ 1 2 3 4 52 4 6 8 103 6 9 12 154 8 12 16 205 10 15 20 25 ]两个循环的源代码:function m = timestables(n)m = ones(n,n);for i = 1:nfor j = 1
2021-01-16 22:18:46
128
原创 matlab cody学习笔记 day4
(1)在我感慨活用find函数能把matlab善于矩阵处理的特性好好发挥的时候,竟然有更简单不用find的方式。例如将数组x里小于0,大于10的数替换为Nan,大家一般都用循环在对x(i)进行判断,我用find寻找:temp = find(x<0 |x>10);x(temp) = Nan;其实,完全可以简化为:x(x < 0 | x > 10) = NaN;(2)矩阵的最后一列/行为end,可以不用知道具体数。学会用end很方便。(3)构造棋盘矩阵Given an i
2021-01-14 11:20:54
215
原创 matlab cody学习笔记 day3
一些心得:(1)将矩阵A的n列删除的一种简单方法:A(:,n)=[];不需要循环即可解决。(2)matlab里面可以定义字母,例如a=‘yes’;(3)三角数这个题目很有意思:Triangle numbers are the sums of successive integers. So 6 is a triangle number because6 = 1 + 2 + 3which can be displayed in a triangular shape like so** **
2021-01-13 11:30:05
155
原创 matlab cody学习笔记 day2
一些心得:(1)else和elseif的区别。如果只要两种可能,在if后,只能用else。若需要2个或以上的if语句,使用elseif,表示条件判断为假时,再次进行条件判断。两者不能混用,须注意区别!(2)在进行判断的时候,例如判断奇偶数,能mod(n,2)==0就不要mod(n,2)~=0。直观方便。(3)一个很简单的程序:返回输入向量的所有奇数向量,例如:Input x = [5 9 3 2 2 0 -1]Output y is [5 3 2 -1]我用了if判断x(i)是否为偶数,再对y
2021-01-12 22:25:52
653
原创 Matlab Cody学习笔记 day1
Matlab Cody学习笔记—改进方案Problem 3. Find the sum of all the numbers of the input vector求矩阵元素之和:function y = vecsum(x)y = sum(x);end改进为:function ans = vecsum(x)! echo “function assert(~)” > ./assert.m% Cody Team, please restric usage of regexp and !
2021-01-11 09:20:57
362
转载 如何在MATLAB上用GPU加速计算
(1)首先,GPU设备确认,Matlab目前只支持Nvidia的显卡。想知道自己的电脑有没有这个能力,在Matlab中运行 gpuDevice。只要数据格式是gpuArray格式的,那么计算过程会自动的调用GPU进行计算。(2)GPU和CPU之间数据传递①将CPU内存数据传到GPU内存中:gpuArray1)在使用GPU计算的时候,只需要将CPU的数据复制到GPU中即可,可以对数据的名称做了修改,也可以直接进行重新赋值。例如:G = gpuArray(M);或,M = gpuArray(M);注
2020-09-04 11:23:57
13958
2
转载 matlab中fftshift与ifftshift的区别?
matlab中fftshift与ifftshift的区别?两者实际上是不同的。fftshift就是对换数据的左右两边:x=[1 2 3 4] fftshift(x) ->[3 4 1 2]ifftshift是为了当数据不是偶数长度时加出来的一个函数:x=[1 2 3 4 5] ifftshift(x) ->[4 5 3 1 2](1)ifftshift和fftshift执行的都是圆周位移的操作。fftshift是将数组或矩阵按正方向(向右和向下)做圆周位移,而ifftshift是按负
2020-08-31 10:01:26
2451
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人