Answered
switch within if statement vs if/elseif efficiency
Use whichever one is clearest for understanding the program. You will spend more time reading and fixing the code than one |if| ...

9 years ago | 1

| accepted

Answered
How to sort strings by lenght?
Simpler: >> [~,idx] = sortrows(A~=32); >> A(idx,:) ans = Ada adam cesar berit bertil

9 years ago | 0

Answered
Undefined function or variable inside a for loop within a function
The input argument is named |pair_list| (with an underscore), but in the code you use |pairlist| (without underscore).

9 years ago | 1

Answered
I have a 100x100 matrix, i need average of 10-10 row values, so that my matrix become 10x100
This is actually really simple with |reshape|. Here is an example with a 6x4 matrix where I average every 3 rows to give a 2x4 m...

9 years ago | 0

Answered
Adding data to two matrices for indexing
>> Z = [1,9;6,1]; >> cell2mat(arrayfun(@(m)m-3:+1:m+3,Z,'uni',0)) ans = -2 -1 0 ...

9 years ago | 0

| accepted

Answered
How do I combine character strings and numeric arrays using fprintf?
>> C = {'Anna','Bob','Charly','Diane'}; >> M = rand(4,3); >> D = [C(:),num2cell(M)]'; >> fprintf('%8s %8f %8f %8f\n',...

9 years ago | 0

Answered
Length of runs of same number in an array
>> V = [-1,-1,0,0,0,-1,1,-1,1,1]; >> diff(find([1,diff(V),1])) ans = 2 3 1 1 1 2

9 years ago | 0

| accepted

Answered
I have created folders using an array 1-6 and loaded the CSV file now I want to save data from CSV file to the folder in form of text file.. kindly help me
You can use exactly the same code as I gave you in <https://www.mathworks.com/matlabcentral/answers/365093-i-get-error-while-rea...

9 years ago | 0

| accepted

Answered
Converting letters to numbers in an array and vice versa
>> letter2number = @(c)1+lower(c)-'a'; >> letter2number('t') ans = 20 >> letter2number('a') ans = 1...

9 years ago | 3

| accepted

Answered
Switch two random elements in a vector
>> x2 = x1; >> v = randi(numel(x2),1,2); >> x2(v) = x2(v([2,1]))

9 years ago | 0

| accepted

Answered
How do I extract even rows and columns from any Matrix of size n?
>> M = [3 2 1; 1 4 6; 2 2 4; 1 9 7]; >> M(all(~rem(M,2),2),:) ans = 2 2 4

9 years ago | 0

| accepted

Answered
I get Error while reading CSV file.
Note that that is not a CSV file, because the fields are not separated by commas. Judging by the header and the two tabs per row...

9 years ago | 0

| accepted

Answered
How to write a script for the following?
>> for k=1:9, n=sscanf(sprintf('%d',1:k),'%d'); fprintf('%d x 8 + %d = %d\n',n,k,n*8+k); end 1 x 8 + 1 = 9 12 x 8 + 2 = ...

9 years ago | 0

| accepted

Answered
`find` function turn out a error Matrix dimensions must agree
You define a variable named |circularity|, but then try to use one called |circularities|. I suspect that this is mistake, and t...

9 years ago | 0

| accepted

Answered
How to index a matrix with existing array?
Simply use <https://www.mathworks.com/help/matlab/ref/num2cell.html |num2cell|> and <https://www.mathworks.com/help/matlab/ref/s...

9 years ago | 1

| accepted

Answered
Issue with removing space from char from loaded data
I don't have any problems importing your sample file (attached) as numeric data. Here are the two ways I tried: *Method one: ...

9 years ago | 0

| accepted

Answered
How to copy anti diagonal elements to another matrix?
Here is a simple solution using linear indexing. It assumes that both matrices are square and the same size. >> A = randi(8...

9 years ago | 2

| accepted

Answered
assignin and eval functions
You totally misunderstand the issue if you think that |eval|, |evalin| or |assignin| are faulty. There is nothing wrong with ...

9 years ago | 3

| accepted

Answered
Summation of functions in a loop
Creating an array of functions is a red herring. You just need *one* simple array, inside *one* function: >> fun = @(x) sum...

9 years ago | 1

| accepted

Answered
sum of matrix omitting one dimension
Here is one very simple way: >> d = 3; % dimension >> v = 1:ndims(K); >> v([1,d]) = v([d,1]); >> s = sum(reshape(p...

9 years ago | 0

| accepted

Answered
Why do I get different results for this division?
_"I thought that the operation 1/a/b was always equal to 1/(a*b). "_ Mathematically they are the same. But for numeric comput...

9 years ago | 0

| accepted

Answered
Difference between String and Value
I guess you are asking about something like <https://www.mathworks.com/help/matlab/ref/uicontrol.html |uicontrol|> objects. The ...

9 years ago | 1

| accepted

Answered
Start every iteration of for loop with same matrix
Simply make a copy inside the loop, and work on the copy only: for n = 1:length(x) y = x; y(:,n) = Inf; ...

9 years ago | 0

| accepted

Answered
How to use \n and \t with sprintf to set the string of a ui control
The <https://www.mathworks.com/help/matlab/ref/matlab.ui.control.uicontrol-properties.html UIcontrol properties> help page expla...

9 years ago | 0

Answered
rgb2lab color conversion
Either convert the input argument to |uint8| or divide it by 255 and you will get the correct output. Many MATLAB color/image fu...

9 years ago | 0

| accepted

Answered
Find the value of x such that the determinant of A is zero.
There is no need to use symbolic operations, a simple numeric calculation can give you the answer: >> fun = @(x)[2,8,5;2,2,...

9 years ago | 2

Answered
vertcat elements of structure
You can use a <https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html comma-separated list>, no loop is re...

9 years ago | 1

| accepted

Answered
scale to percentage using maximum value
>> 100*A/max(A) ans = 0.46081 14.59551 100.00000 0.36907

9 years ago | 0

| accepted

Answered
How do you divide each row by its first nonzero element?
>> A = [4,9,7;0,2,4;0,0,5]; >> B = bsxfun(@rdivide,A,diag(A)); >> B(1,:) = A(1,:) B = 4 9 7 0 1 2...

9 years ago | 0

| accepted

Load more