octave

Implementing 'curly' and 'access' “chaining” functions in matlab

六眼飞鱼酱① 提交于 2019-12-01 20:51:37
I read this article on the mathworks blog about functional programming in matlab, and two of the helper functions there were: paren = @(x, varargin) x(varargin{:}); curly = @(x, varargin) x{varargin{:}}; The obvious third one to complete the trio (and in keeping with the five-letter theme) would be: acces = @(x, field) x.(field); Putting the discussion of whether it's a good idea to implement chaining in this manner or not in matlab aside (note: octave supports chaining by default), paren seems to work well, as expected; however, curly and acces have a major drawback; consider the following

How to exit GNU Octave, after running an m file, without closing plot windows?

℡╲_俬逩灬. 提交于 2019-12-01 20:37:49
I have been writing a C++ program to solve the problem of the simple pendulum and then plot the result using GNU Octave. It plots the result via this line in my program: system("./simppenadj.sh"); where simppenadj.sh is: #!/bin/sh octave --no-gui --persist -q simppenadj.m and simppenadj.m is: #!/usr/bin/octave # Plotting simppenadj.txt A = importdata('simppenadj.txt'); B = importdata('simppenadjdx.txt'); t = A(:,1); theta = A(:,2); dtheta = B(:,2); figure plot(t,theta) xlabel('t','FontSize',16,'FontWeight','bold') ylabel('\theta','FontSize',16,'FontWeight','bold') title('{d^{2}\theta}/{d{t^{2}

Splitting string by number of characters matlab

最后都变了- 提交于 2019-12-01 19:44:03
Is there any builtin function in Matlab that cuts string by the number of characters and returns it as a cell array or something. For example if call A = some_function(string, 3): Input: string = '1234567890' Output: A = {'123', '456', '789', '0'} or do I need to use loops? Thanks. A little long may be: ns = numel(string); n = 3; A = cellstr(reshape([string repmat(' ',1,ceil(ns/n)*n-ns)],n,[])')' An alternative solution, which is slightly more elegant (in my opinion), would be using regexp : A = regexp(str, sprintf('\\w{1,%d}', n), 'match') where str is your string and n is the number of

urlread(), urlwrite() don't work for https pages in Octave for Windows

北城余情 提交于 2019-12-01 18:32:47
When I use Octave 3.8.1 installed in Cygwin, I can successfully download https pages like this: urlwrite('https://www.google.com', 'downloaded.html') However, when I use Octave 3.6.4 installed in Windows 7 SP1 Pro 64bit, urlwrite() doesn't work: octave-3.6.4.exe:18> urlwrite('https://www.google.com', 'downloaded.html') error: urlwrite: curl: Problem with the SSL CA cert (path? access rights?) urlread() has the same problem. Is there a good way to avoid this error? Update: Following Andy's advice, I tried to fix a curl-related problem. At the moment, curl.exe can work for https, but libcurl (I

import function in octave

為{幸葍}努か 提交于 2019-12-01 18:30:35
I am running matlab code in octave. The import function is not implemented in core octave, I guess. Any idea how to use this matlabe function in octave? Here is what I have: octave-3.4.0:7> setup Importing packages: brml.* warning: the `import' function is not yet implemented in Octave Please read ` http://www.octave.org/missing.html ' to learn how you can contribute missing functionality. error: `import' undefined near line 8 column 5 You can make your own custom import.m. From http://octave.1599824.n4.nabble.com/namespace-support-td1638758.html : function import(varargin) error(nargchk(1,

link PHP with Octave or Matlab

和自甴很熟 提交于 2019-12-01 18:02:19
问题 Suppose I have a lot of math calculations which are quite tedious to implement in php. Is it possible to somehow link PHP and Octave on the server in such a way, that php sends parameters to Octave and receives answers back. Has anyone tried anything similar? 回答1: Another solution is to use octave-daemon, which was written specifically for this purpose. Works on Linux, don't know about Windows. 回答2: You can use matlab compiler to make an executable matlab application, that you can call from

link PHP with Octave or Matlab

☆樱花仙子☆ 提交于 2019-12-01 17:44:54
Suppose I have a lot of math calculations which are quite tedious to implement in php. Is it possible to somehow link PHP and Octave on the server in such a way, that php sends parameters to Octave and receives answers back. Has anyone tried anything similar? Another solution is to use octave-daemon , which was written specifically for this purpose. Works on Linux, don't know about Windows. You can use matlab compiler to make an executable matlab application, that you can call from php. GNU Octave can be called from PHP using the Linux command line, using commands like exec() or passthru() .

Loopless function calls on vector/matrix members in Matlab/Octave

若如初见. 提交于 2019-12-01 17:42:59
I came into matrix world from loop world (C, etc) I would like to call a function on each individual member of a vector/matrix, and return the resulting vector/matrix. This is how I currently do it: function retval = gauss(v, a, b, c) for i = 1:length(v) retval(i) = a*(e^(-(v(i)-b)*(v(i)-b)/(2*c*c))); endfor endfunction Example usage: octave:47> d=[1:1000]; octave:48> mycurve=gauss(d, 1, 500, 100); Now, all advice on MATLAB/Octave says: STOP whenever you catch yourself using loops and think of a better way of doing it. Thus, my question: Can one call a function on each member of a vector

Finding the shortest repetitive pattern in a string

久未见 提交于 2019-12-01 17:39:18
I was wondering if there was a way to do pattern matching in Octave / matlab? I know Maple 10 has commands to do this but not sure what I need to do in Octave / Matlab. So if a number was 12341234123412341234 the pattern match would be 1234 . I'm trying to find the shortest pattern that upon repetiton generates the whole string . Please note: the numbers (only numbers will be used) won't be this simple. Also, I won't know the pattern ahead of time (that's what I'm trying to find). Please see the Maple 10 example below which shows that the pattern isn't known ahead of time but the command finds

Undefined argument when declaring function in Octave

自作多情 提交于 2019-12-01 17:34:21
I get undefined variable/argument when trying to define my own random generator function. Code: function result = myrand(n, t, p, d) a = 200 * t + p big_rand = a * n result = big_rand / 10**d return; endfunction mrand = myrand(5379, 0, 91, 4) error: >> myrand error: 't' undefined near line 2 column 15 error: called from myrand at line 2 column 7 You can't start a script with a function keyword. https://www.gnu.org/software/octave/doc/v4.0.1/Script-Files.html This works: disp("Running...") function result = myrand(n, t, p, d) a = 200 * t + p big_rand = a * n result = big_rand / 10**d return;