octave

Optimizing the value N to split arrays up for vectorizing an array so it runs the quickest

巧了我就是萌 提交于 2019-12-11 05:07:01
问题 I'm trying to optimizing the value N to split arrays up for vectorizing an array so it runs the quickest on different machines. I have some test code below #example use random values clear all, t=rand(1,556790); inner_freq=rand(8193,6); N=100; # use N chunks nn = int32(linspace(1, length(t)+1, N+1)) aa_sig_combined=zeros(size(t)); total_time_so_far=0; for ii=1:N tic; ind = nn(ii):nn(ii+1)-1; aa_sig_combined(ind) = sum(diag(inner_freq(1:end-1,2)) * cos(2 .* pi .* inner_freq(1:end-1,1) * t(ind)

How to normalize an image using Octave?

允我心安 提交于 2019-12-11 05:02:09
问题 In their paper describing Viola-Jones object detection framework (Robust Real-Time Face Detection by Viola and Jones), it is said: All example sub-windows used for training were variance normalized to minimize the effect of different lighting conditions. My question is "How to implement image normalization in Octave?" I'm NOT looking for the specific implementation that Viola & Jones used but a similar one that produces almost the same output. I've been following a lot of haar-training

Octave, display image received by socket connection does't show

折月煮酒 提交于 2019-12-11 04:55:01
问题 I have an octave script in which i open a socket server an receive some commands from connected clients. This already works. Now i need to send data to Octave, mostly images and process them. To test this i wanted to receive and display a grayscale test image. bufflen = 4096; [data,count]=recv(b,bufflen); imshow (data) the image window opens but it is empty. The size of data is exactly the size of the image file i am sending. I also tried saving the image with imwrite (data, "test.jpg"); this

MATLAB finding max. of a struct

Deadly 提交于 2019-12-11 02:04:45
问题 I am trying to find max value of a struct but max([tracks(:).matrix]) does not work. It gives me the following error: "Error using horzcat CAT arguments dimensions are not consistent." Do you have an idea? Here is what my struct looks like: tracks = 1x110470 struct array with fields: nPoints matrix tracks.matrix includes 3D points. For example here is tracks(1,2).matrix: 33.727467 96.522331 27.964357 31.765503 95.983849 28.984663 30.677082 95.989578 29 回答1: You can use array fun, followed by

Logisitic Regression Cost Function

笑着哭i 提交于 2019-12-10 23:42:00
问题 function [J, grad] = costFunction(theta, X, y) m = length(y); h = sigmoid(X*theta); sh = sigmoid(h); grad = (1/m)*X'*(sh - y); J = (1/m)*sum(-y.*log(sh) - (1 - y).*log(1 - sh)); end I'm trying to compute the cost function for logistic regression. Can someone please tell me why this isn't accurate? Update: Sigmoid function function g = sigmoid(z) g = zeros(size(z)); g = 1./(1 + exp(1).^(-z)); end 回答1: As Dan stated, your costFunction calls sigmoid twice. First, it performs the sigmoid function

Vectorize the sum of outer products of coresponding columns of two matrices using Matlab/Octave

本小妞迷上赌 提交于 2019-12-10 22:45:03
问题 Suppose I have two matrices A and B which are made up of column vectors as follows. A = [a_1,a_2,...,a_N]; B = [b_1,b_2,...,b_N]; Is there any way to vectorize the calculation of the sum of outer products for every column in A with the corresponding column in B. Here is my non-vectorized solution. S = zeros(size(A,1), size(B,1)); for n=1:N S = S + A(:,n)*B(:,n)'; % S = S + a_n * b_n' end Any help would be greatly appreciated. 回答1: you are not clear on what N is, but I assume that N = number

cat of two struct: not the same fields

烂漫一生 提交于 2019-12-10 22:30:02
问题 I have multiple csv files a.csv field_a, field_b 111, 121 112, 122 b.csv field_a, field_c 211, 231 212, 232 c.csv field_a, field_b, field_c 311, 321, 331 312, 322, 332 And i would like to concatenate them output.csv field_a,field_b,field_c 111, 121, NA 112, 122, NA 211, NA, 231 212, NA, 232 311, 321, 331 312, 322, 332 I would like to do this with octave. What i did so far: a=csv2cell(a.csv) A=cell2struct(a(2:end,:),a(1,:),1) and now i'm looking for something like merge(A,B,C) or vertcat(A,B,C

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

ぐ巨炮叔叔 提交于 2019-12-10 20:53:20
问题 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'

Octave crashes when printing a plot

纵饮孤独 提交于 2019-12-10 20:44:47
问题 Solution : As suggested by user Andy in the comments, an update to the newest version of Octave (at the moment: octave-4.0.1-rc4) fixed the problem and the plot could be saved as PNG. I have a large-ish amount of data that I plot in Octave. But when I try to save the image, the program crashes without any explanation or real error message. My Octave is version 4.0 and it's running on Win 8.1, the graphics_toolkit is qt . Saving smaller amounts of data has worked so far, but somehow I seem to

Fold function in Octave

荒凉一梦 提交于 2019-12-10 19:27:55
问题 Is there standard implementation of fold (reduce, aggregate etc) for one dimensional vector in Octave? If no, is there any way to express fold without using a loop statement? 回答1: The miscellaneous package provides the function reduce. For example, octave:6> reduce(@(x,y)(x*y), [1:5]) ans = 120 If you look at the source code for reduce , you'll see that it is a fairly simple Octave function that is implemented with a for loop, so it won't be more efficient than implementing the reduction with