Answered
Multiply pages of 3D array with each other
A = rand(512,10,16); [m,n,N]=size(A); pairs=nchoosek(1:N,2); B=zeros(m,n,size(pairs,1)); for k=1:size(B,3) B(:,:,k) =...

6 years ago | 1

| accepted

Answered
Sharing with somebody who hasnt Matlab
MATLAB compiler

6 years ago | 0

| accepted

Answered
How to plot circle with direction?
2D version. adapt to your need % circle parameter r = 5; cx = 0; cy = 0; cfun = @(tt) [cx+r*cos(tt); cy+r*sin(tt)]; xy...

6 years ago | 4

Answered
Fast computation of an equation.
The efficientcy of the bellow method depend on m, n, s % Generate dummy test data m = 1000; n = 1000; s = 1000; W = rand(m,...

6 years ago | 1

| accepted

Answered
Calculate the distance squared of a point in 3d space
function [distanceSquared] = PixelDistance(P,Q) P1 = P(1); P2 = P(2); P3 = P(3); Q1 = Q(1); Q2 = Q(2); Q3 = Q(3); distanceSqu...

6 years ago | 0

Answered
Counting number of same neighbourhood pixels between two matrices.
This command counts the number of 3x3 neigbouring pixels that exactly match conv2(p1==p2,ones(3),'same')

6 years ago | 0

Answered
Comparing a value against a set of values
if any(A,3) % ... end

6 years ago | 1

Answered
Time in hr min sec to seconds
Purely arithmetics x=str2double('152605'); h=floor(x/1e4); y=mod(x,1e4); m=floor(y/1e2); s=mod(y,1e2); nsec=polyval([h,m,...

6 years ago | 0

Answered
Time in hr min sec to seconds
polyval(str2num(reshape('152605',2,3)'),60)

6 years ago | 0

Answered
Time in hr min sec to seconds
round((datenum('152605','HHMMSS')-datenum('000000','HHMMSS'))*86400)

6 years ago | 1

Answered
Why is fprintf not printing the first whitespace in a string?
Read carefully FPRINTF document; the first argument after optional fid is a a FORMAT; not arguments. So you must add '%s' fprin...

6 years ago | 0

| accepted

Answered
How can I establish that my function must have a fixed value after a specific condition occurs?
Assuming your T contains 1,2,3. V = [0.5, 0, 1]; % values correspond to 1,2,3 S = V(T)

6 years ago | 0

Answered
Attribute number to closed area
You might checkout POLYSHAPE, that can give you the regions P = polyshape(rand(10,2)); R = regions(P); close all plot(R); ...

6 years ago | 0

| accepted

Answered
How to plot a position heatmap inside a circle?
Hide the ouside with a patch close all im=peaks; % your heatmap imagesc(im) ax = gca; xl = xlim(ax); yl = ylim(ax)...

6 years ago | 1

Answered
Raising a matrix to a power
% This script will generate a plot of pressure P (in bar) as a function of molar % volume V (in cm^3/mol) for various values of...

6 years ago | 0

Answered
How to compute the ratio of the insection point in each grid on the boundary of a real structure
Assuming the boundary has one connexed piece x=-3:12; y=-3:10; [X,Y]=meshgrid(x,y); cx = 4; cy = 3; r = 5; Z = (X-c...

6 years ago | 1

| accepted

Answered
How to merge words in the cells to form a string
a_=a'; % then copy screen followed by useless screen capture. Please do a__ = a(1:10); save(' a__.mat','a__'); and attach t...

6 years ago | 0

Answered
Sorting points based on comparing distances.
You might learn to use Delaunay triangulation that can find nearrest points much more efficiently than pdist2 or such (applicabl...

6 years ago | 0

Answered
I wish to open a saved figure in the figure number of my choice.
clear close all fig=figure(); plot(rand(1,10)); hgsave(fig,'myfig.fig'); input('type <CR> to continue and see load file <...

6 years ago | 0

Answered
Generate 50000 binary sequence of 16 bits long (without repetition) without using "rand(1,16) > 0.5" logic
c=dec2bin(randperm(2^16,50000)-1,16) a=c-'0' % if you need binary arrays

6 years ago | 1

| accepted

Answered
How can we create two vectors have normally distributed random entries with zero mean?
I correct the flaw of dpb method U=randn(10,1); V=randn(10,1); ps=U.'*V; a=sqrt(abs(ps)); U=(sign(ps)/a)*U; V=(1/a)*V;

6 years ago | 2

| accepted

Answered
How to merge words in the cells to form a string
A={{"happy" "birdday"} {"I" "am" "a" "boy"} {"good" "boy"}}; S = strtrim(string(char(cellfun(@(c) sprintf('%s ',c{:}), A, 'un...

6 years ago | 0

Answered
Updating constraints in fmincon at while loop
The number of non-linear constraints can be dynamically changed during the run of FMINCON. You can then set the OutputFun, trac...

6 years ago | 0

| accepted

Answered
reshaping a 3D array
[m,n,p] = size(Colours); ColoursRearrange = reshape(permute(reshape(Colours,m,n,3,[]),[1 2 4 3]),[m n p]);

6 years ago | 0

Answered
How to resolve this error Error using fprintf Function is not defined for 'cell' inputs.
Not sure the formatting display you want, I simply fix some of issues your code so it can run n=6; C1i={[0],[1 2 4],[2 3 4]...

6 years ago | 0

Answered
Anomalous histogram for small argument
Yes it is a BUG. I chase back and in the file C:\Program Files\MATLAB\R2019a\toolbox\matlab\datafun\+matlab\+internal\+math\bin...

6 years ago | 2

| accepted

Answered
How to improve the accuracy of lu decomposition?
If you want to check accuracy of LU decomposition you should check unitless quantity error = norm(L*U-A) / norm(A) norm(.) is...

6 years ago | 0

| accepted

Answered
How extract a specific digit from binary number
b(end-flip(7:10)+1)

6 years ago | 0

Answered
how to change a number of base n to base m
>> dec2base(124,5) ans = '444' >> dec2base(122,4) ans = '1322' >> base2dec('1444',5) ans = 24...

6 years ago | 0

Answered
changing a matrix size
% A is 144 x 144 input binary matrix I512 = logical(interp2(... linspace(0,1,size(A,2)),... linsp...

6 years ago | 0

| accepted

Load more