Answered
How can I make a column appending columns which are of size of sum of other column?
>> lat = [1,2,3,4,5]; >> CG = [5,10,20,11,12]; >> V = cell2mat(arrayfun(@(v,n)v*ones(n,1),lat(:),CG(:),'uni',0)) V = 1 ...

8 years ago | 0

| accepted

Answered
Reshape the Matrix to complex number ?
Some methods to get the original (complex) matrix back: Method one: reshape and matrix multiplication: Y = reshape(Xd,[],2)*[1...

8 years ago | 0

| accepted

Answered
regex not working to replace numbers with enclosing brackets numbers
>> regexprep('t1 w1 r2 (L2) d1 L12aa','([twLr])(\d+)','$1($2)') ans = 't(1) w(1) r(2) (L(2)) d1 L(12)aa' You might also like t...

8 years ago | 0

Answered
Create a character cell in ascending order
N = 1000; C = cell(1,N); for k = 1:N C{k} = sprintf('variable%d',k); end

8 years ago | 0

Answered
How to skip some values in for loop ?
Just add this line after those loops: I_dd(B==0) = 0 to get this: I_dd(:,:,1) = 1 4 5 6 0 0 7 0...

8 years ago | 1

| accepted

Answered
Problem introducing user input into an array
Simpler: bny = input('Insira o codigo a codificar: ' ,'s'); idx = ismember(bny,'01'); assert(all(idx),'Input must contain onl...

8 years ago | 0

| accepted

Answered
Taking the kronecker product of multiple matricies, nested in an array
A = [1,1;0,1]; B = [1,0;1,0]; C = {A,B,B,A,A,B}; S = C{1}; for k = 2:numel(C) S = kron(S,C{k}); end

8 years ago | 0

| accepted

Answered
Table: Overwrite column value with condition
This might work: myTable.a(myTable.a < 3) = 0;

8 years ago | 1

| accepted

Answered
Understanding indexing and the colon operator
The end keyword simply refers to the last column (it can also be used for rows, etc.): https://www.mathworks.com/help/matlab/re...

8 years ago | 1

| accepted

Answered
Concatenating data from structure array for plotting
Nested structures do not allow that syntax, so the simplest solution is to use temporary variables to unnest those structures (t...

8 years ago | 0

| accepted

Answered
Read numbers and characters from text file into a single array
opt = {'CollectOutput',true}; fmt = '%f%f%*s%f%*s%f%f%f'; [fid,msg] = fopen('test.txt','rt'); assert(fid>=3,msg) C = textsca...

8 years ago | 0

Answered
convert cell array to structure with first row as field names
Use cell2struct, possibly something like this (where C is your cell array): S = cell2struct(C(2:end,:),C(1,:),1)

8 years ago | 0

| accepted

Answered
How can I access my command history without running Matlab program?
The command history is stored in either: history.xml (R2014a or later) history.m (earlier versions) https://www.mathworks.com...

8 years ago | 1

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...

8 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

8 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...

8 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 ...

8 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 ...

8 years ago | 0

| accepted

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

8 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 ...

8 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...

8 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(...

8 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 ...

8 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 ...

8 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 ...

8 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...

8 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 ...

8 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

8 years ago | 0

| accepted

Load more