Answered
reorder the data array for the least distance
You can easily use <https://www.mathworks.com/help/matlab/ref/sortrows.html |sortrows|> to get a _very similar_ sequence, which ...

8 years ago | 0

Answered
Concatenate arrays of different length into a matrix
*Truncate to shortest length using indexing:* >> N = min(numel(A),numel(B)); >> [A(1:N);B(1:N)] ans = NaN 2...

8 years ago | 3

| accepted

Answered
Dynamically get list of switch cases in code
_"Is something like this possible..."_ Possible, yes. Easy, no. Getting the |switch| conditions dynamically requires parsi...

8 years ago | 1

| accepted

Answered
sum of array elements with specific condition?
>> fliplr(cumsum(fliplr(A))) ans = 9 8 8 7 6 6 5 5 4 4 4 3 2 1

8 years ago | 0

| accepted

Answered
Predict y values from x values
_"Predict y values from x values"_ If you want a better fit to the actual data than fitting a curve, then just use <https://w...

8 years ago | 2

Answered
Rearranging assigned data in a required order
That is just basic indexing: Bnew = B(A) <https://www.mathworks.com/help/matlab/math/matrix-indexing.html>

8 years ago | 1

| accepted

Answered
How do convert array x to array z?
If you want to convert the first value, whatever it may be, to 1, the second to 2, etc: >> x = [4 4 8 8 8 5 5 4 8 8 4]; ...

8 years ago | 2

| accepted

Answered
what wrong with this code
The line that defines C6 is commented out: %C6=(R_min/(Tooldia*Sover/100))/(R_max/(Tooldia*Sover/100)); uncomment that l...

8 years ago | 0

| accepted

Answered
Loading .tab in loop, varying header length and number of columns
This imports the requested three columns of data from your sample files, ignoring everything before the |*/| line. It uses the d...

8 years ago | 0

| accepted

Answered
Saving Images in a Cell Array
There are several problems, such as that you have not converted the |row| and |col| character data to numeric (indexing must be ...

8 years ago | 0

| accepted

Answered
For Loop for matrix input array (without sum)
_"but why doesn't below work?"_ Because you overwrite the results of every loop iteration with the results of the next iterat...

8 years ago | 0

| accepted

Answered
Alternative to "round" for accurate accumulation
>> n = fzero(@(k)sum(round(A*k))-7,[0.01,100]) n = 3.4811 >> V = round(A*n) V = 3 2 2 0 0 >> sum(V)...

8 years ago | 0

| accepted

Answered
Error in interp1 (line 117) extptids = Xq < X(1) | Xq > X(end);
The problem is very simple: the index |jj| is empty, so you are trying to interpolate empty data (which clearly is impossible: h...

8 years ago | 0

| accepted

Answered
Detecting new .txt file in a folder how can i read all the files through fileread command
You used the wrong kind of indexing, because if |nameslist| is a cell array then parentheses returns a cell array: y = file...

8 years ago | 1

Answered
How can I embed tab characters in datetime string formats?
Much more efficient than post-processing the dates is to just define the <https://www.mathworks.com/help/matlab/ref/datetime.htm...

8 years ago | 0

| accepted

Answered
Creating Subfolders in a loop?
Your code has several features that need to be fixed, such as your using |%d| format specifier with a character vector, use of t...

8 years ago | 4

| accepted

Answered
Transferring all columns in all text files in a folder and graphing data
The basic problem is that you are not providing the directory when you read the file data, so whatever function you use will onl...

8 years ago | 0

| accepted

Answered
Find all and modify triplicates in an array
This is a simple example of how you could approach this problem. I have not dealt with the edge cases: this is a simple proof-of...

8 years ago | 0

Answered
How do I make a user defined function with the input being the file name in a string?
Sure, this is easy (do NOT use the name |power|, as this is already used by MATLAB): function myfun(filename) data = csv...

8 years ago | 0

| accepted

Answered
Vectorisation of 2 2d matrix
For MATLAB <https://blogs.mathworks.com/loren/2016/10/24/matlab-arithmetic-expands-in-r2016b/ versions R2016b+>: C = A - re...

8 years ago | 0

| accepted

Answered
How to sort the files obtained by ImageDatastore?
I don't know if it is possible to sort the ImageDatastore object itself, but you can certainly sort the filenames yourself: one ...

8 years ago | 3

| accepted

Answered
How do you create a matrix Aij where each value is determined by a formula?
[I,J] = ndgrid(1:2,1:2); (-1).^(I+J)

8 years ago | 1

| accepted

Answered
how can I make a vector with some functions as its elements? I mean, for example [x, x^2, sin x, tan x, sqrt(x)] and give i to that. if i were 1 the function x and when were 4 function tan (x) get active and get in the calculations.
To avoid unnecessary symbolic calculation, simply define a <https://www.mathworks.com/help/matlab/cell-arrays.html cell array> o...

8 years ago | 0

Answered
Why iterations cannot be defined before a 'for' loop
Your first example follows the syntax shown in the <https://www.mathworks.com/help/matlab/ref/for.html |for|> help: for ind...

8 years ago | 0

Answered
How to create a random permutation that has specific values in a specific place?
One simple solution is to keep generating permutations until one matches your requirements: C = {'G','G','A','G','B','G','G...

8 years ago | 0

| accepted

Answered
How to deal with a vector containing numbers and characters?
_"how can I compute the minimal set of numbers S such that each row of M has at least one number belonging to set S?"_ You co...

8 years ago | 1

| accepted

Answered
How to give an option to user of where to save the generated file
Just use <https://www.mathworks.com/help/matlab/ref/fullfile.html |fullfile|> like this, each time you call any function that re...

8 years ago | 0

| accepted

Answered
Extracting row of a matrix based on maximum value of a column element
>> mat = [... 1978 7 1 45 1 1978 7 11 50 2 1978 7 14 100 2 1978 7 23 120 3 1978 8 17 150 4 1978 8 23 130 5 ...

8 years ago | 0

| accepted

Answered
Permutation of variables with different states - get all combinations
*Download* Jos's excellent <https://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb-varargin |allcomb|>, and use it l...

8 years ago | 3

Answered
Logical operation on column of a matrix
Here are a few methods to try: >> A = [0,0,0,0,1,0;0,0,0,1,0,0;1,0,0,0,0,1;0,0,1,1,1,1;0,1,0,1,1,0] A = 0 0 0 ...

8 years ago | 0

| accepted

Load more