Check out my website: www.matzjb.se for tips on various coding-related problems.

Professional Interests: image processing, algorithms, computer graphics, high performance computing.

Answered

reason for converting image into double

The reason is precision. Say you read an image using (write this in the Matlab prompt) >>Im = imread('filename'); >>clas...

reason for converting image into double

The reason is precision. Say you read an image using (write this in the Matlab prompt) >>Im = imread('filename'); >>clas...

5 years ago | 1

Answered

why slow 5 times when tic or toc and expression in one line?

Funny enough I also get horrible timings. I am using Matlab 2014a and I get: Elapsed time is 1.053381 seconds. Elapsed t...

why slow 5 times when tic or toc and expression in one line?

Funny enough I also get horrible timings. I am using Matlab 2014a and I get: Elapsed time is 1.053381 seconds. Elapsed t...

6 years ago | 0

| accepted

Answered

How can I fill a matrix column with dta coming from another matrix according to index

Without knowing the size of the matrix, it might be a good idea to use a sparse matrix, instead of filling the non existant elem...

How can I fill a matrix column with dta coming from another matrix according to index

Without knowing the size of the matrix, it might be a good idea to use a sparse matrix, instead of filling the non existant elem...

6 years ago | 1

| accepted

Answered

Permutation of array elements

This seems to work A = {'test a 1', 'test a 2'}; B = {'test b 1', 'test b 2'}; WAKE = [A',B'] %see below for explanat...

Permutation of array elements

This seems to work A = {'test a 1', 'test a 2'}; B = {'test b 1', 'test b 2'}; WAKE = [A',B'] %see below for explanat...

6 years ago | 0

| accepted

Answered

How to perform skull stripping using matlab?

I found something that might be of help: <http://se.mathworks.com/help/matlab/visualize/exploring-volumes-with-slice-planes.htm...

How to perform skull stripping using matlab?

I found something that might be of help: <http://se.mathworks.com/help/matlab/visualize/exploring-volumes-with-slice-planes.htm...

6 years ago | 1

Answered

using mex -setup error

As the error message says you are missing a suitable compiler to create mex files. See <http://se.mathworks.com/help/matlab/matl...

using mex -setup error

As the error message says you are missing a suitable compiler to create mex files. See <http://se.mathworks.com/help/matlab/matl...

6 years ago | 0

Answered

How can I insert row into matrix without deleting its values?

The only way I know of is to create a new matrix consisting of A and the row and then append the three matrices together, for in...

How can I insert row into matrix without deleting its values?

The only way I know of is to create a new matrix consisting of A and the row and then append the three matrices together, for in...

6 years ago | 11

| accepted

Answered

How to solve the problem Ax=b, when A is (14400,14400) and b (14400,1)?

If A is full \ has to perform a Gaussian elimination. A is ~1.5GB in double precision and it seems that \ requires at least that...

How to solve the problem Ax=b, when A is (14400,14400) and b (14400,1)?

If A is full \ has to perform a Gaussian elimination. A is ~1.5GB in double precision and it seems that \ requires at least that...

6 years ago | 0

Answered

I was record on my phone a sound. how to hear that sound in matlab.

I found a matlab script (with exe and library) that can import m4a files. I tried it and it seems to work. See <http://www.ee.co...

I was record on my phone a sound. how to hear that sound in matlab.

I found a matlab script (with exe and library) that can import m4a files. I tried it and it seems to work. See <http://www.ee.co...

6 years ago | 0

| accepted

Answered

how can obtain min of matrix

This solution is maybe a little ugly, but it works Say that A is the matrix. tmp = A; %we will destroy elements, ...

how can obtain min of matrix

This solution is maybe a little ugly, but it works Say that A is the matrix. tmp = A; %we will destroy elements, ...

6 years ago | 0

Answered

How to solve this equation?

This is actually very simple using the *\* operator, see <http://se.mathworks.com/help/matlab/ref/mldivide.html mldivide,\ docum...

How to solve this equation?

This is actually very simple using the *\* operator, see <http://se.mathworks.com/help/matlab/ref/mldivide.html mldivide,\ docum...

6 years ago | 0

| accepted

Answered

Multi-Line Colors in 2014

That's odd. I'm using Matlab R2014a and it seems to be working fine. Are you using Matlab R2014b?

Multi-Line Colors in 2014

That's odd. I'm using Matlab R2014a and it seems to be working fine. Are you using Matlab R2014b?

6 years ago | 1

Answered

what is the difference between a vector and a matrix?

A matrix is simply a rectangular array of numbers and a vector is a row (or column) of a matrix. Read more about the practica...

what is the difference between a vector and a matrix?

A matrix is simply a rectangular array of numbers and a vector is a row (or column) of a matrix. Read more about the practica...

6 years ago | 3

| accepted

Answered

How can I get different 2D Matrices from a 3D matrix?

The size of the A(1,:,:) will be a 1-by-n-by-z matrix, so you have to temporarily store it in a 2d matrix tmp(:,:) = A(1,:,...

How can I get different 2D Matrices from a 3D matrix?

The size of the A(1,:,:) will be a 1-by-n-by-z matrix, so you have to temporarily store it in a 2d matrix tmp(:,:) = A(1,:,...

6 years ago | 0

| accepted

Answered

how to crop an image

In my answer I throw away the green and blue channels of the PNG, because it is black/white. If you want to use a color image, t...

how to crop an image

In my answer I throw away the green and blue channels of the PNG, because it is black/white. If you want to use a color image, t...

6 years ago | 2

Answered

How to read data one by one

It should be sufficient to write filename='coordinates.txt'; [x,y,z] = dataread('file', filename, '%f%f%f', 'del...

How to read data one by one

It should be sufficient to write filename='coordinates.txt'; [x,y,z] = dataread('file', filename, '%f%f%f', 'del...

6 years ago | 0

| accepted

Answered

FFT manual help formulation

The range 1:50 is only used in the plot, not in the rest of the example. See <http://se.mathworks.com/help/matlab/ref/fft.html ...

FFT manual help formulation

The range 1:50 is only used in the plot, not in the rest of the example. See <http://se.mathworks.com/help/matlab/ref/fft.html ...

6 years ago | 0

Answered

Replacing non-alphabetic characters with numbers?

Yet another answer, just for the "cellfun" of it ;-) tmp = cellfun(@(x) isstrprop(x, 'alpha'), {TS1}, 'UniformOutput', fals...

Replacing non-alphabetic characters with numbers?

Yet another answer, just for the "cellfun" of it ;-) tmp = cellfun(@(x) isstrprop(x, 'alpha'), {TS1}, 'UniformOutput', fals...

6 years ago | 0

Answered

how can i read hdr file?

Have you tried http://www.mathworks.se/help/images/ref/hdrread.html?

how can i read hdr file?

Have you tried http://www.mathworks.se/help/images/ref/hdrread.html?

6 years ago | 0

Answered

Assigning colors on a cylinder

Simplest way [x,y,z] = cylinder; surface(x,y,z, 'FaceColor','texturemap',... 'EdgeColor','none','Cdata', rand(10)...

Assigning colors on a cylinder

Simplest way [x,y,z] = cylinder; surface(x,y,z, 'FaceColor','texturemap',... 'EdgeColor','none','Cdata', rand(10)...

6 years ago | 1

| accepted

Answered

How to find first ten prime numbers that are greater than 4?

You could do it like this x = primes(100); %pick primes smaller than, say 100 x = x(x>4); %pick the ones larger than 4 ...

How to find first ten prime numbers that are greater than 4?

You could do it like this x = primes(100); %pick primes smaller than, say 100 x = x(x>4); %pick the ones larger than 4 ...

6 years ago | 0

| accepted

Answered

Why aren't my cases working correctly

I would put period and t calculation outside of the switch and I think you want t = linspace(0,period*cycles,100);

Why aren't my cases working correctly

I would put period and t calculation outside of the switch and I think you want t = linspace(0,period*cycles,100);

6 years ago | 0

Answered

Index through datestring, selecting whole hours

Another alternative where I just pick the last two characters from the first column of the cell: %mock data: cel{1,1...

Index through datestring, selecting whole hours

Another alternative where I just pick the last two characters from the first column of the cell: %mock data: cel{1,1...

6 years ago | 0

Answered

How can I improve Matlab perfomance for this code?

It seems to me that combntns (which is the same as nchoosek) is taking a long time to finish. So, the appending of the combinati...

How can I improve Matlab perfomance for this code?

It seems to me that combntns (which is the same as nchoosek) is taking a long time to finish. So, the appending of the combinati...

6 years ago | 0

| accepted

Answered

how to integrate inside 'for' loop

To solve this problem you can use a anonymous function handle to a function with x and n as arguments. f = @(x) myfun(x, ...

how to integrate inside 'for' loop

To solve this problem you can use a anonymous function handle to a function with x and n as arguments. f = @(x) myfun(x, ...

6 years ago | 0

| accepted

Answered

Plotting a 3D matrix graph

First, I assume that the graph is undirected, edges are going both ways, but you might want to change that maybe. A =...

Plotting a 3D matrix graph

First, I assume that the graph is undirected, edges are going both ways, but you might want to change that maybe. A =...

6 years ago | 0

| accepted

Answered

access values in dataset

LinearModel is using tables, so you can write tmp = table2array(Im.Coefficients) and access tmp.

access values in dataset

LinearModel is using tables, so you can write tmp = table2array(Im.Coefficients) and access tmp.

6 years ago | 0

Answered

Color code with dash line

x=1:10; plot(x, cos(x), ':','color',[0,0.5,0],'linewidth',3)

Color code with dash line

x=1:10; plot(x, cos(x), ':','color',[0,0.5,0],'linewidth',3)

6 years ago | 2

| accepted

Answered

what does c(:).' mean? c should be a vector

By writing c(:)' you are making sure that the vector has the dimension 1xn, where n is the length of the vector, a row vector. H...

what does c(:).' mean? c should be a vector

By writing c(:)' you are making sure that the vector has the dimension 1xn, where n is the length of the vector, a row vector. H...

6 years ago | 1

| accepted

Answered

how to create 200 random matrices using loop..

I have not tried it but something like this: n=200; tmp = rand(32,32,n); and then to multiply each matrix for i...

how to create 200 random matrices using loop..

I have not tried it but something like this: n=200; tmp = rand(32,32,n); and then to multiply each matrix for i...

6 years ago | 0