Answered
How can I convert a cell to a matrix ?
The simple and efficient approach: X = reshape([output{:,1}],260,207); y = reshape([output{:,2}],260,207); Z = reshape([outpu...

6 years ago | 0

| accepted

Answered
make matlab read the files in order?
Adapting from the examples in the NATSORTFILES documentation: .. S = dir(fullfile(myFolder,'shape_0*.txt')); S = natsortfiles...

6 years ago | 0

| accepted

Answered
fprfintf for matrices and rounding
A = [1,2,3;4,5,6;7,8,9]; fprintf('%5.2f %5.2f %5.2f\n',A.')

6 years ago | 0

| accepted

Answered
Extracting values from string using regexp
The problem is not extracting the numbers (which is easy) but in knowing which of the numbers has been extracted, which is not a...

6 years ago | 1

Answered
sscanf how to skip lines - not textscan!!!
"Is there a way to skip the first X lines in a text file when reading a text file using sscanf?" No, because sscanf parses stri...

6 years ago | 0

Answered
Find the indices of one variable in another one avoiding NaNs
The C you showed in your example is not possible as it has different numbers of elements in each row, but you could put the data...

6 years ago | 0

| accepted

Answered
Changing variable name within a nested for loop by looping end number in the variable name.
It is very important to learn the correct terminology for your data, because this makes it much much easier to find information ...

6 years ago | 0

| accepted

Answered
How can I read csv file data correctly? I tried multiple ways
textscan has no problems importing the file data simply and efficiently (sample file is attached): opt = {'Delimiter',',','Coll...

6 years ago | 0

| accepted

Answered
Merging two arrays based on index arrays
z_index = [2,3]; y_index = [4,1,5]; z(z_index) = [1,3]; y(y_index) = [-2,4,2]; x(z_index) = z(z_index); % RHS = [1,3] x(y...

6 years ago | 1

| accepted

Answered
Cell 2 Multidimensional Array Conversion
out = permute(cat(3,A{:}),[3,1,2]); https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://www.m...

6 years ago | 0

| accepted

Answered
how to use fprintf in matlab?
"I tried this in matlab and got the same result." The fprintf documentation states that "If you specify a conversion that does ...

6 years ago | 0

Answered
Function Calculates Fibonacci Numbers
n = 13; prv = 0; out = 1; for k = 3:n [out,prv] = deal(out+prv,out); % replace |+| with your function NNIADD disp(o...

6 years ago | 0

Answered
cell array with numeric values only
Do NOT use loops or cellfun for this, unless you really want to write complex and slow MATLAB code. The most efficient solution...

6 years ago | 0

Answered
How to replace a character in matlab
vocals = ["a"; "e"; "i"; "o"; "u"; "y"; "ae"; "oe"; "aa"]; for k = 1:numel(vocals) fnm = sprintf('%s.wav',vocals(k)); ...

6 years ago | 0

| accepted

Answered
How to convert array so that I have only numerical values
Do NOT use cellfun for this, unless really you want your code to be slow. The most efficient solution by far is this: str = {'...

6 years ago | 0

Answered
Insert elements into vector
index = [1;2;4;5;6;8;9]; index_val = [11;25;3;4;56;7;9]; removed_index = [7,3]; % simpler to use a numeric array removed_va...

6 years ago | 1

| accepted

Answered
How to generate a random decimal number between -1 and 1?
The inputs to rand define its output size, not the output value range. Its range is fixed to 0..1, but you can adjust generate o...

6 years ago | 0

| accepted

Answered
coverting string to ascii value in Matlab
"the letter 'a' is 61 why in matlab i get NAN?" Because that is the wrong way to get the ASCII value (or character code, to be ...

6 years ago | 3

| accepted

Answered
Operator '==' is not supported for operands of type 'cell'.
Use strcmpi instead of testing for character equality.

6 years ago | 2

Answered
Sorting Vector A in Ascending order and apply the same steps to Vector B
[A,X] = sort(A) B = B(X)

6 years ago | 1

| accepted

Answered
Subtracting 2 cells in an array
>> -diff(A) ans = -2 -2 3 -4 5 >> sum(-diff(A)) ans = 0

6 years ago | 0

| accepted

Answered
Format Array column in fprintf
The short answer is: not easily. Your output example has varying numbers of fractional digits 0.000000 % six decimal places 4...

6 years ago | 0

| accepted

Answered
Preallocating a cell array of chars?
A = cell(3,1); A(:) = {''} This assigns one scalar cell (on the RHS) to all of the cells in the array A: https://www.mathwork...

6 years ago | 3

| accepted

Answered
Format number in fprintf
I am guessing that unlike your example you actually want the columns to be aligned, e.g. where M is your matrix: >> fprintf(' %...

6 years ago | 0

| accepted

Answered
How do I replace Matrix elements
Use AND instead of OR: >> A = [-1,0,4,6;1,1,0,2;-7,0,5,0;5,1,5,1] A = -1 0 4 6 1 1 0 2 -7 0 5 0 ...

6 years ago | 0

Answered
How can I get the secondary diagonal of a matrix?
diag(fliplr(A))

6 years ago | 0

| accepted

Answered
Find words common across multiple string cells
My ancient version does not support strings, so I used cell arrays of character vectors, but I would expect that this should wor...

6 years ago | 0

| accepted

Answered
Function with Non Constant Variable
You could create an anonymous function: fun = @(x) S(3,1,x,2); .. fun(17)

6 years ago | 0

Answered
How can I change the first row of my matrix to all 0s using a for loop?
Where M is your matrix: M(1,:) = 0;

6 years ago | 0

Answered
How to form a structure array variable?
Simpler using indexing: vec = {'a','b','c'}; Test{1}.(vec{Ind}) https://www.mathworks.com/help/matlab/matlab_prog/generate-fi...

6 years ago | 0

Load more