Categories
Development MATLAB

Printing n choose k combinations in matlab

I need to create an algorithm in matlab which returns any combination of n subset from the k set. For example I have a set {1,2,3,4,5} and I need any combination of 3 numbers included in this set. So this function should returns: [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], […]

Categories
CSV Development MATLAB

histogram plot from a csv file in matlab

I really need help in the histogram plot from a csv file format. When I searched in the internet for histogram it was suggested hist function. In the following example hist is working only for x or y but not both. close all data = csvread(‘mc_10000_better.csv’,4); % Read the data y = data(:,1) ; x […]

Categories
Development MATLAB

How to remove bias when downsampling a vector in Matlab

I have a set of vectors containing some arbitrary shape like a triangle pulse with a single maxima. I need to downsample these vectors by an integer factor. The position of the maxima relative to the length of the vector should stay the same. Below code shows, that when I do this, there is a […]

Categories
Development MATLAB

Can we configure MATLAB let variable have minium local scope?

Can we configure MATLAB let variable have minium local scope? I want matlab something similiar like C below. % after some configure … for i=1:1:100 a=i*i end % here we can not using ‘a’ any more for it have local scope in for loop. Why I want it becase the scope in whole script sometimes […]

Categories
Development Linux MATLAB Python Ubuntu

Equivalent of MATLAB’s pretty() in python?

Well I would like to know if there is any function (or C code that I can define) that does the same as pretty() in MATLAB. so when I run this in MATLAB: syms s k; G1=16/(s+0.8); H=k; Ga=G1/(1+G1*H); G2=1/s; Gb=Ga*G2; M=Gb/(1+Gb); M=collect(M); %basically this part of the code pretty(M); %is what I want to […]

Categories
Development MATLAB

Matlab – How to implement backward Euler’s method?

I am trying to implement these formulas: Forward Euler’s method: this is what I have tried: x_new = (speye(nv)+ dt * lambda * L) * x_old; Is there anything wrong with this? How can I calculate this using sparse operation? Backward Euler’s method: I have tried this: x_new = (speye(nv)- dt * lambda * L) […]

Categories
Development MATLAB

Matlab – How to implement backward Euler’s method using sparse matrix?

I am trying to implement these formulas: Forward Euler’s method: this is what I have tried: x_new = (speye(nv)+ dt * lambda * L) * x_old; Is there anything wrong with this? How can I calculate this using sparse operation? Backward Euler’s method: I have tried this: x_new = (speye(nv)- dt * lambda * L) […]

Categories
Development MATLAB

Optimal way of doing iterative assembly of sparse matrices in Matlab?

My code needs to in a loop modify the elements of a sparse matrix. Doing this matlab warns me that This sparse indexing expression is likely to be slow. I am preallocating the sparse arrays using the Spalloc function but am still getting this warning. What is the optimal approach for assembling of sparse matrices? […]

Categories
Development MATLAB

Turning an image into grayscale and Deuteranomaly scale in Matlab

I want to turn an image from its original RGB scale to grayscale and deuteranomaly. However, every attempt I try gives me somewhat darker image that does not truly display grayscale.My attempt for grayscale here is what im running whe = imread(‘CoWheel.png’); whesi = size(whe); red = []; gree = []; blue = []; for […]

Categories
Development MATLAB Python

converting between matlab and python [on hold]

I am new in python. pleae tell me How I can convert this matlab file to python, classdef TGrid < handle properties % properties common for all grids NzEarth % number of Earth layers Nza % number of air layers end methods %set airLayers for the grid function obj = setAirLayers(obj,varargin) Method = ‘fixed height’; […]