Showing posts with label MATLAB. Show all posts
Showing posts with label MATLAB. Show all posts

Monday, September 17, 2018

MATLAB: vision.ShapeInserter crashes in Arch Linux

Seems its same problem as here: https://au.mathworks.com/matlabcentral/answers/364727-why-does-matlab-crash-on-linux-fedora-26-with-a-segmentation-violation-r2017b-or-later#answer_289066

Solution was to remove libfreetype files from /opt/MATLAB/R2016a/bin/glnxa64

sudo mv libfreetype* exclude/

Sunday, April 29, 2018

Start MATLAB in Linux termianal

alias mat="/opt/MATLAB/R2016a/bin/matlab -softwareopengl -nodesktop -nosplash"

Thursday, February 09, 2017

Sunday, January 22, 2017

MATLAB: Run using xfce4 launcher without termianl window

Add -desktop parameter, e.g., /opt/MATLAB/R2016a/bin/matlab -desktop

Tuesday, May 03, 2016

Ubuntu16:04: Matlab cant change font size on plots

xorg fonts need to be installed. sudo apt install xfonts-100dpi xfonts-75dpi

Wednesday, April 20, 2016

Ubuntu 16.04 and Matlab 2016a: MATLAB has encountered an internal problem and needs to close

There is some problem with matlab UI GPU-based rendering on nvidia as this is causing this problem
Stack Trace (from fault):
[ 0] 0x00007f5bbc4a024d /usr/lib/nvidia-361-updates/libGLX_nvidia.so.0+00344653


The workaround is to launch matlab without GPU rendering: opt/MATLAB/R2016a/bin/matlab -softwareopengl

Wednesday, August 14, 2013

Matlab: split vector into number of parts of roughly the same size

%split into 3 parts
chunckCell=splitvect(1:10, 3);
chunckCell{:}
ans = 1 2 3 ans = 4 5 6 7 ans = 8 9 10

Tuesday, July 02, 2013

Matlab: deal - assign values in vector into variables

Mex files in Matlab for linux: failed to map segment from shared object: Operation not permitted

This happens when you have no permissions to execute given file or library. In my case it was happening because I was trying to run mex files using Matlab for linux that were located in NTFS partition. Often the partition is mounted in linux without exec arguments. To fix it, I edited my /etc/fstab file and aded exec argument to the line responsible for mounting NTFS partition:

UUID=F4B664646C02A51D /mnt/c ntfs users,defaults,exec 0 0

Monday, July 01, 2013

Problems with libstdc++.so.6 when compiling mex files in Matlab 2013a x64 on Xubuntu 13.04 x64

Problem compiling mex files in Matlab 2013a x64 on Linux (Xubuntu 13.04 x64):/usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus: /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/x86_64-linux-gnu/libppl_c.so.4) /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus: /usr/local/MATLAB/R2013a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by /usr/lib/x86_64-linux-gnu/libppl.so.12)

The problem was that Matlab was linking libstdc++.so.6 (located in /usr/local/MATLAB/R2013a/sys/os/glnxa64) to the file it provides, i.e. libstdc++.so.6.0.13 (located in /usr/local/MATLAB/R2013a/sys/os/glnxa64).

This is the old version of libstdc++, and xubuntu has newer version, i.e. libstdc++.so.6.0.17 (located in /usr/lib/x86_64-linux-gnu).

Thus, I solved this problem by changing the symbolic link in Matlab to point to the new version:cd /usr/local/MATLAB/R2013a/sys/os/glnxa64
sudo mv libstdc++.so.6 libstdc++.so.6_org
sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17 libstdc++.so.6

Sunday, April 25, 2010

bash: send a command to a screen session

"Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells." It is a very useful tool, that I often use, as it allows me to run "multiple terminals in one" even when I log out from the system.

So how to send command to screen session from other terminal. In other words how to remote-control a screen session from within a script. This post is useful for this.

In particular, I wanted to execute matlab scripts in screen windows. To do this I used the following:
1. Create screen sessionscreen -S matlab2. Create few windows in the screen session using Ctr-a c
3. Send matlab command to each as followsfor ((i=0;i<$NO_WINDOWS;i+=1)); do
echo $i
sleep 2
screen -S matlab -p $i -X exec matlab -nodesktop -r "bashCalculations('part',$i+1)"
done
where bashCalculations is my matlab script bashCalculations.m that takes part argument. So,, each screen window executes different part of my script.

Monday, March 08, 2010

Matlab: Convert numerical array to cell with string representation of numbers

Short Matlab script that takes an array (i.e. vector) of numbers and returns cell with fileds that are string representation of the numbers in the array.For example: >> a=[1 2 3.24 -43 4.56];
>> numarray2cellstring(a)

ans =

'1' '2' '3.24' '-43' '4.56'

Monday, November 09, 2009

Effect size of matched and unmatched data in Maltab

"In statistics, an effect size is a measure of the strength of the relationship between two variables in a statistical population, or a sample-based estimate of that quantity" from here.

The script below calculates effect size for matched (paired) and unmatched (unpaired) data as described in [1].

So, if C and E sets are matched than effect size d is 1.265. If C and E sets are unmatched than effect size d is also 1.265. The two sizes are equal for this example only.

References

[1] Dunlop, W. P., Cortina, J. M., Vaslow, J. B., & Burke, M. J. (1996).
Meta-analysis of experiments with matched groups or repeated measures designs. Psychological Methods, 1, 170-177.

Saturday, November 07, 2009

Useful Matlab / Octave script to make default function arguments easier


The lack of an easy way of making default function arguments in MATLAB (I have R2007a) was annoying me for a long time. Octave (current version 3.2), which is an open source equivalent of MATLAB is much better in terms of handling default function arguments.

What I mean, can be explained best by simple example.

So, lets define a very simple m file, called testDefaultArguments.m with the following function.
function testDefaultArguments(a=1,b=2)
fprintf(1,'a=%d, b=%d\n',a,b);
We see that we have a function called testDefaultArguments with two arguments a and b, and we assign default values to them, i.e. 1 and 2, respectively. Such syntax seems to be helpful, because you can execute testDefaultArguments function as follows:octave-3.2.3:40> testDefaultArguments()
a=1, b=2
octave-3.2.3:41> testDefaultArguments(3)
a=3, b=2
octave-3.2.3:42> testDefaultArguments(a=43)
a=43, b=2
octave-3.2.3:43> testDefaultArguments(a=43,5)
a=43, b=5
octave-3.2.3:44> testDefaultArguments(a=43,b=55)
a=43, b=55
So everything seems good, but what if you want to assign only value to b, and not to a?Lets tryoctave-3.2.3:47> testDefaultArguments(b=55)
a=55, b=2 %!!! a is 55 and not b !!! This is strange
So, this is not only strange, but can easily leads to bugs in one's code.

So this was Octave. What about MATLAB? The anwser is: Error! The function testDefaultArguments can't be executed in Matlab (at least in R2007a and R2008a) due to syntax errors!

So, to help myself with making default function arguments in both MATLAB and Octave I made getfunargs.m script, which makes working with default function arguments little easier (To be honest, this function is a modification of getargs.m script). I'm not going to explain how it works, instead I'm just going to show how it can be used.

Lets define function called testDefaultArguments2 which uses getfunargs:function testDefaultArguments2(varargin)

defaults = struct(...
'a',1,...
'b',2 ...
);

args = getfunargs(defaults, varargin);

fprintf(1,'a=%d, b=%d\n',args.a,args.b);
Now, the testDefaultArguments2 can be executed both in MATLAB and Octave as follows:octave-3.2.3:52> testDefaultArguments2()
a=1, b=2
octave-3.2.3:53> testDefaultArguments2('a',3)
a=3, b=2
octave-3.2.3:54> testDefaultArguments2('b',5)
a=1, b=5
octave-3.2.3:55> testDefaultArguments2('b',5,'a',2)
a=2, b=5
It can bee seen now, that the default arguments work as expected.

Wednesday, November 04, 2009

Performance benchmark script for MATLAB and Octave

The benchmark script evaluates MATLAB and Octave not only in execution times for matrix manipulation, but also for integration, 2D interpolation, solving nonlinear equation, reading/writing files, plot creating and saving, image manipulation (e.g. rotation, filtering, erosion).

The execution times of each test (27 tests for now) are normalized against times obtained using MATLAB 7.4.0.287 (R2007a) on Intel Mac OS X 10.4.11 (Intel Core Duo
2GHz, 2GB RAM).

As a results the script generates txt file with the time values (normalized and not normalized) obtained for each test.

The evaluate overall performance of MATLAB/Octave geometric and arithmetic means of the individual time values obtained are used.

The header
function res = mybench(varargin)
% res = mybench('noOfRepeats', 3,...
% 'normalize',true,...
% 'onlyTests',[],...
% 'imagep',true)
%
% Benchmark script for MATLAB and Octave.
% Tested on Matlab 2009a and Octave 3.2.2 for Windows.
%
% Execution time of basic matrix manipulation function is tested along with
% integration, solving nonlinear equation, image processing functions ( if
% available), saving/loading matrices to a file system, for loop,
% binary operation,etc. In total 27
% tests are performed (less if image processing functions not available).
%
% All results are normalized against the results obtained
% using MATLAB 7.4.0.287 (R2007a) on Intel Mac OS X 10.4.11 (Intel Core Duo
% 2GHz, 2GB RAM)
%
% At the end, arithmetic and geometric means of the times obtained are
% calculated. All results obtained are stored in a txt file named
% results_.txt.
%
% INPUT
% noOfRepeats - int - number of times each test is executed (default 3)
% normalize - boolean - normalize results (default true).
% onlyTests - int vector - do only tests given (default [], i.e. do all tests)
% imagep - boolean - do or not image processing testing
%
% OUTPUT
% res - struct - normalized geometric mean .
%
% EXAMPLES
% res = mybench(); %perform all tests with default settings.
% res = mybench('noOfRepeats',10); %perform all tests 10 times.
% res = mybench('onlyTests',[1,5,8]); %perform only tests 1,5 and 8.
% res = mybench('noOfRepeats', 1,'normalize',false); % repeat 1 time
% %each tests and do not
% %normalize results.
%
% Site: http:\\shortrecipes.blogspot.com
% Date: Nov 2009

The full code is here.
Example output from the script is as follows:



Friday, October 30, 2009

Comparing two methods of measurement in Matalb or Octave

How to compare two methods that measure the same variable? How to check if one method produces results constantly higher than the other method and if the difference is significant? How to determine whether new method, can replace the old one? The anwser to these question lies in the analysis of bias between the two method of measurement [1]. Below is a Matlab implementation of Ordinary least products (OLP) regression analysis [1] that can be used to anwser to these questions.

function res = mgr(X,Y,varargin)
% res = mgr(X,Y)
% Mean Geometric Regression (i.e. Ordinary least products (OLP) regression)
%
% Used to evaluate two measurement methods in terms of fixed and
% proportional bias as described in [1].
%
% INPUT
% X - vector of values calculated by the first method.
% Y - vector of values calculated by the second method.
% boolean - plot or not scattergram of the values
% string - label of x axis of scattergram
% string - label of y axis of scattergram
%
%
% EXAMPLE from [1]:
%
% M1=[132 138 144 146 148 152 158 130 162 168 172 174 180 180 188 194 194 200 200 204 210 210 216 220 220];
% M2=[130 134 132 140 150 144 150 122 160 150 160 178 168 174 186 172 182 178 196 188 180 196 210 190 202];
%
% res=mgr(M1,M2)
%res =
%
% a: 13.9506
% b: 0.8611
% a_CI95: [-6.9476 32.3364]
% b_CI95: [0.7576 0.9788]
%
% res=mgr(M1,M2,true); % produces scattergram
% res=mgr(M1,M2,true,'SBP(M1)','SBP(M2)'); % produces scattergram with x and y axis
% % labels of 'SBP(M1)' and 'SBP(M2)'
%
% NOTE:
% The above calculated values of a and b agree with the values in [1]
% Values of CI95 are marginally different, becouse, as expalined in [1],
% they are calculated using approximate formulas.
%
%REFERENCE:
%[1] J Ludbrook, Comparing methods of measurement, Clinical and
% Experimental Pharmacology and Physiology, 1997:24,193-203
%
%
%
Full code of the above script is here.
Script was tested on Matlab 2007a and in Octave 3.2. En example of the scattergram that is generated by the script is below. This scattergram is the same as an example given in [1].

References

[1] J Ludbrook, Comparing methods of measurement, Clinical and Experimental Pharmacology and Physiology, 1997:24,193-203.

Monday, July 06, 2009

Update of CentOS 5.2 to CentOS 5.3

There was no problems with the update. I just followed the instructions. Most importantly, after the update to CentOS 5.3, applications previously installed in CentOS 5.2 worked (i.e. Ansys 11SP1, Matlab 2008b, Mathematica 7, Abaqus 6.8).