Skip to content

Instantly share code, notes, and snippets.

clc
clear all;
close all;
%testing matlab script on github gist
@shaybensasson
shaybensasson / crosscorr_n_conv_sample.matlab
Last active August 29, 2015 14:16
cross correlation and convolution animation sample
% Authors
% Reza Arfa <rezaarfa (at)gmail.com>
%
% License
% The program is free to use for non-commercial and academic purposes.
%
% Changes
% 01/01/2013 (!)
clc; close all; clear all;
a = [ 1 2 3 4' ];
b = padarray(a,[0 3], NaN, 'pre')
b = padarray(b,[0 4], NaN, 'post')
@shaybensasson
shaybensasson / get sorted eigvals and eigvects.matlab
Created March 4, 2015 08:59
get sorted eigvals and eigvects
%A=[5,8,16;4,1,8;-4,-4,-11]; %real eigvects
%http://math.mit.edu/~gs/linearalgebra/ila0601.pdf
A=[.8,.3;.2,.7];
[V,D] = eig(A);
[evals,idx] = sort(diag(D));
EigenValues = evals
evects = V(:,idx);
EigenVects = evects
@shaybensasson
shaybensasson / play a sound at the end of a simulation.matlab
Created March 4, 2015 09:00
play a sound at the end of a simulation
load gong
sound(y,Fs)
% based on http://stackoverflow.com/questions/22792020/matlab-accumarray-weighted-mean
data = [10 1;30 1;20 2;30 1;20 4;20 6]
%{
data =
10 1
30 1
20 2
@shaybensasson
shaybensasson / remove NaN columns or rows.matlab
Created March 4, 2015 09:03
remove NaN columns or rows
% see http://www.mathworks.com/matlabcentral/answers/68510-remove-rows-or-cols-whose-elements-are-all-nan
out = A(:,any(~isnan(A))); % for columns
out = A(any(~isnan(A),2),:); %for rows
%% filter range of values
rawData = 1900:5:2100;
from = 1982;
to_excluded = 2015;
indexes = 1:length(rawData);
%declare indexes for the whole data range
filter = logical(rawData(:) >= from & rawData(:) < to_excluded);
@shaybensasson
shaybensasson / reshape, repmat and bsxfun.matlab
Created March 4, 2015 09:05
reshape, repmat and bsxfun
%% using reshape() to change a multi dimensional array into a smaller
% dimension without loosing values
%vector into matrix 5x2 (rowxcol)
A = 1:10;
B = reshape(A,[5,2])
%reshape matrix to have 3 columns, discarding rows
A = magic(6);
B = reshape(A,[],3)
@shaybensasson
shaybensasson / matrix|array|vector manipulation.matlab
Created March 4, 2015 09:06
matrix|array|vector manipulation
%acessing and slicing
a=[1 2;3 4]
%{
a =
1 2
3 4
%}