Answered
How to find index in a single array?
Simpler: A = [3;4;6;9;12;34;56;99;105;190]; B = [4;12;34;56]; D = randi(999,200,7); % fake data E = D(B,:); F = D(setdiff(A...

7 years ago | 1

| accepted

Answered
I want to know how to assing variable value depending on the value it self. Explained in detail below.
This is MATLAB, so just keep it simple: >> x = [2,3,5]; >> r = zeros(1,max(x)); >> r(x) = x r = 0 2 3 0 5

7 years ago | 0

| accepted

Answered
writetable does not replace file
According to the writetable help, "If filename is the name of an existing spreadsheet file, then writetable writes a table to th...

7 years ago | 1

| accepted

Answered
Filling an array with recursive function
I don't see why you need to use a recursive function: M = 3; B = randi(9,M,M,M); I = zeros(M,M,M); for ku = 1:M for kv ...

7 years ago | 1

| accepted

Answered
how to extract unique pixels from on image?
>> I = randi(7,5,4,3) % MxNx3 image array. I(:,:,1) = 3 2 5 5 7 3 6 3 6 7 6 4 5 6 4 5 ...

7 years ago | 0

| accepted

Answered
Changing colourmap with user input - specifying number of colours
Use str2func: str = 'pink'; fun = str2func(str); fun(128)

7 years ago | 1

| accepted

Answered
Can you find the error in this code that aims to sum the digits of a string?
Simpler: str = '12361927' while numel(str)>1 num = sum(str-'0') str = num2str(num) end Prints this in the command ...

7 years ago | 1

| accepted

Answered
Does make it faster in calculation if i write the variables as letter rather than words ?
The variable name legnth is unlikely to make any noticeable difference to code execution speed, but the only way to be sure is t...

7 years ago | 0

| accepted

Answered
Matrix value to store as matrix index
Without loops, works for any version: A = [2,2,1,1,1;3,3,3,0,2;5,4,5,0,3] S = size(A); C = repmat(1:S(2),S(1),1); Z = zeros(...

7 years ago | 0

Answered
How can I successively put a number before and after a vector?
A simple recursive function does the trick (although there might be simpler solutions): function M = myrec(V) if numel(V)>1 ...

7 years ago | 1

| accepted

Answered
logspace with gap of half
>> V = logspace(-3,4,8); >> V = [V;5*V]; >> V = V(1:end-1) V = 0.001 0.005 0.010 0.050 0.100 ...

7 years ago | 0

| accepted

Answered
what will be the short and efficient code for my this task...kindly help me i am new to matlab
>> I = randi(9,5) % fake data (use your data matrix) I = 2 8 5 4 5 7 6 5 8 8 9 1 9 6 8 ...

7 years ago | 0

| accepted

Answered
How to check if each two successive rows are identical?
Just use basic indexing and logical operations: >> A = [1,2,3;1,2,3;4,5,6;4,5,7] A = 1 2 3 1 2 3 4 5 6...

7 years ago | 1

| accepted

Answered
Function 'subsindex' is not defined for values of class 'audioplayer'
You have a variable named play: play.folder play.name If you have an object named play then you cannot (easily) use the play ...

7 years ago | 2

| accepted

Answered
Why do I get the error Array indices must be positive integers or logical values when using the sin function?
You named a variable sin. Clear your workspace of this variable, e.g.: restart MATLAB, or run this command: clear sin

7 years ago | 0

| accepted

Answered
Reading in file as cell array in a two dimensional [1x1] structure
Use the CollectOutput option: opt = {'CollectOutput',true}; fmt = '%s%s%s%s%s%s%s%s%s%s'; C = textscan(fid,fmt,opt{:}); C = ...

7 years ago | 0

| accepted

Answered
specified numbers of random permutation of a vector
Where V is your vector: idx = randperm(n); V(idx(1:100))

7 years ago | 0

Answered
I have an idea that I want to write in MATLAB language
"Is there a way that makes MATLAB finds the x that crossponds to fh and fL ... ?" You could use indexing: >> M = [8,9;10,11;8,...

7 years ago | 0

| accepted

Answered
How to count NaN elements in n dimentional matrix, using counter in loop?
Where A is your array: cnt = 0; for k = 1:numel(A) cnt = cnt+isnan(A(k)); end

7 years ago | 0

Answered
compute the mean of matrices with different dimensions
Z = nan(2370,512,3); Z(:,1:512,1) = A; Z(:,1:512,2) = B; Z(:,1:256,3) = C; mean(Z,3)

7 years ago | 0

| accepted

Answered
Try to make a function for deflection and is just dosen`t want to work.
Simpler: >> W = 8500; % max load (N) >> E = 42000; % elastic modulus (N/mm^2) >> I = 10e6; % ??? (mm^4) >> Dfun = @(L) (W*...

7 years ago | 1

| accepted

Answered
Creating a matrix showing the binary units of the numberline from 0 to (2**n)-1
a = 0:7; b = dec2bin(a)-'0' % ^^^^ if you want to get a numeric array

7 years ago | 0

| accepted

Answered
Find and reduce a numeric array with identical columns
>> [~,X,Y] = unique(tmp(:,[1,3]),'rows'); >> out = tmp(X,:); >> out(:,2) = accumarray(Y,tmp(:,2),[],@sum) out = 119.0000...

7 years ago | 0

| accepted

Answered
Need some help with a while loop
"however, the code seems to loop infinitely many times I guess. I have no clue why? Is there anything wrong with the code??" Yo...

7 years ago | 0

| accepted

Answered
Creating logical arrays based on condition
>> a = [0.5,0.7,0.9]; >> b = [0.3,0.8,0.7]; >> c = [0,1,2]; >> f = c; >> f(a<=b) = -1 f = 0 -1 2

7 years ago | 0

Answered
if in a row i am having 6 numerical values of large number i want convert into binary form of length 10 bits
>> V = [234,567,123,456,900,190]; >> M = dec2bin(V(:),10) M = 0011101010 1000110111 0001111011 0111001000 1110000100 001...

7 years ago | 1

| accepted

Answered
permuting one matrix w.r.t. another matrix
Use sub2ind, e.g.: >> a = [1,2,3;4,5,6;7,8,9;10,11,12] a = 1 2 3 4 5 6 7 8 9 10 11 12...

7 years ago | 0

| accepted

Answered
How to get all possible arrays by randomizing in each cells with four items (1x6 array)
A simple solution with ndgrid: >> x = 99; >> y = 188; >> z = 277; >> C = cell(1,6); >> [C{:}] = ndgrid([0,x,y,z]); >> C = ...

7 years ago | 1

Answered
Sort characters w/ number in a field of struct array
You could download natsortfiles, which now directly sorts the DIR output structure: S = dir(..); S = natsortfiles(S); % alphan...

7 years ago | 1

Load more