octave

gradient descent seems to fail

喜夏-厌秋 提交于 2019-11-28 16:06:48
I implemented a gradient descent algorithm to minimize a cost function in order to gain a hypothesis for determining whether an image has a good quality. I did that in Octave. The idea is somehow based on the algorithm from the machine learning class by Andrew Ng Therefore I have 880 values "y" that contains values from 0.5 to ~12. And I have 880 values from 50 to 300 in "X" that should predict the image's quality. Sadly the algorithm seems to fail, after some iterations the value for theta is so small, that theta0 and theta1 become "NaN". And my linear regression curve has strange values...

What is your favourite MATLAB/Octave programming trick? [closed]

狂风中的少年 提交于 2019-11-28 14:55:36
I think everyone would agree that the MATLAB language is not pretty, or particularly consistent. But nevermind! We still have to use it to get things done. What are your favourite tricks for making things easier? Let's have one per answer so people can vote them up if they agree. Also, try to illustrate your answer with an example. Jason Sundram Using the built-in profiler to see where the hot parts of my code are: profile on % some lines of code profile off profile viewer or just using the built in tic and toc to get quick timings: tic; % some lines of code toc; Directly extracting the

MATLAB/octave count number of operations (flops)

依然范特西╮ 提交于 2019-11-28 14:23:48
Is it possible to report number of operations to evaluate for example matrix/matrix (dense or sparse) in MATLAB or octave. Haven't tried it personally, but the Lightspeed Matlab Toolbox claims to support flops counting. Apparently the flops command was a valid option in MATLAB up through version 5. Not exactly what you're looking for, but you can use profile to get the cpu time for an operation. 来源: https://stackoverflow.com/questions/2868429/matlab-octave-count-number-of-operations-flops

Octave: How to prevent plot window from closing itself?

元气小坏坏 提交于 2019-11-28 14:07:12
From the octave CLI or octave GUI, if I run plot([1,2,3],[1,4,9]) it will display a plot window that I can look at and interact with. If however I create file myPlot.m with the same command as content plot([1,2,3],[1,4,9]) and that I run it with octave myPlot.m then I can briefly see the plot window appear for a fraction of a second and immediatly close itself. How can I prevent this window from closing itself? Octave 4.2.2 Ubuntu 18.04 Here is a full example, given the confusion in the comments. Suppose you create a script called plotWithoutExiting.m , meant to be invoked directly from the

Vectorization for meshgrid in Matlab (or Octave)

为君一笑 提交于 2019-11-28 13:48:05
Vectorized code in Matlab runs much faster than a for loop (see Parallel computing in Octave on a single machine -- package and example for concrete results in Octave) With that said, is there a way to vectorize the code shown next in Matlab or Octave? x = -2:0.01:2; y = -2:0.01:2; [xx,yy] = meshgrid(x,y); z = sin(xx.^2-yy.^2); As pointed out by @Jonas, there are a few options available in MATLAB, and which works best depends on a few factors such as: How large is your problem How many machines you have available Do you have a GPU Does MATLAB already multithread the operations Many elementwise

Differences between Octave and MATLAB? [closed]

感情迁移 提交于 2019-11-28 13:12:36
问题 I'm a programmer who knows Python, Ruby and some C who is trying to decide whether to learn GNU Octave or Matlab. I know that they have a lot in common, but it isn't clear to me how similar the syntax is or even the data structures are. Everyone says they are "similar", but no one says how similar they actually are. The above link shows several examples where they are syntactically similar or identical, is this true for the whole language? I am trying to learn the language in general to do

Generalization of mat2str to cell arrays

落爺英雄遲暮 提交于 2019-11-28 12:04:20
I sometimes miss a function to produce a string representation of a (possibly nested) cell array. It would be a generalization of mat2str , which only works for non-cell arrays (of numeric, char or logical type). Given an array x , how to obtain a string representation y , such that evaluating this string produces x ? For example, the input x = {[10 20], {'abc'; false; true;}}; should produce an output string like y = '{[10 20], {''abc''; false; true}}'; (or some variation regarding spacing an separators), such that isequal(x, eval(y)) is true . This process, transforming a data structure into

matlab, butterworth

只愿长相守 提交于 2019-11-28 11:35:28
问题 I need to apply a Butterworth filter. In order to prove my cutoff frequency, I wish to plot the residuals vs cutoff frequency, as shown in the image on the right: Residuals are computed using the expression shown in the image on the left. I want to apply a second-order low-pass Butterworth filter. My sample frequency is 40 Hz. Using help butter reads: "The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate". This is my code, where x is the unfiltered

Octave/MATLAB: How to compare structs for equality?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 10:47:15
How do I compare two structs for equality in octave (or matlab)? Attempting to use the == operator yields: binary operator `==' not implemented for `scalar struct' by `scalar struct' operations Use either the isequal or isequalwithequalnans function. Example code: s1.field1 = [1 2 3]; s1.field2 = {2,3,4,{5,6}}; s2 = s1; isequal(s1,s2) %Returns true (structures match) s1.field3 = [1 2 nan]; s2.field3 = [1 2 nan]; isequal(s1, s2) %Returns false (NaN ~= NaN) isequalwithequalnans(s1, s2) %Returns true (NaN == NaN) s2.field2{end+1}=7; isequal(s1,s2) %Returns false (different structures) isequal(s1,

How to assign colors to each value in scatter function - GNU Octave

末鹿安然 提交于 2019-11-28 10:08:52
问题 How can I use the scatter function in GNU Octave in order to assign colors to each plotted value ? 回答1: You have to change colormap and 4th parameter of octave's scatter. The parameter is vector 1xn indexing colormap. You can have maximally 255^3 vectors. And how to do that? Example solution: Set colormap (matrix 3 x n), which will contain each color exactly ones Use as 4th parameter vector, which is containing each number exactly ones, and has same size like x and y clf; x = randn (100, 1);