Answered
Question with vectorisation?
Just use <https://www.mathworks.com/help/matlab/ref/randi.html |randi|> and define the output size: A(1:1000,1) = randi(5,1...

8 years ago | 0

Answered
why i cannot genereate the answer?
This: else if a<0 is not really valid MATLAB syntax. The correct syntax is elseif a<0 ^^ no space! written...

8 years ago | 1

Answered
How to use "str2num" ans "strrep" on array of cells?
The biggest problem with your file is not the formatting, but the fact that it uses commas for the decimal radix: MATLAB only su...

8 years ago | 0

| accepted

Answered
For loop with file number
This can be done with <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html dynamic fieldn...

8 years ago | 0

| accepted

Answered
How do i use a pair of nested for loops to store a series of 9 related numbers in a 3x3 matrix?
_"How do i use a pair of nested for loops to store a series of 9 related numbers in a 3x3 matrix?"_ num = str2double(input(...

8 years ago | 0

Answered
index exceed matrix dimension
|files| is empty, so accessing |files{1}| will throw an error. This is very fragile code that assumes that |files| contains at l...

8 years ago | 0

Answered
Re-write repeated values of a matrix using intermediate increased values
Just use <https://www.mathworks.com/help/matlab/ref/interp1.html |interp1|> on each row of your matrix: >> vec = [1,0,0,0,2...

8 years ago | 1

Answered
To find maximum value of any matrix without using built-in max()
function [val,idx] = mymax(arr) val = arr(1); idx = 1; for k = 2:numel(arr) if arr(k)>val val = ar...

8 years ago | 1

| accepted

Answered
How to extract multiple text files and take average of each three for only one row of each txt file?
This will extract the requested data from multiple text files: D = 'directory where the files are stored'; S = dir(fullf...

8 years ago | 0

| accepted

Answered
How to properly apply cellfun in this case - text spliting
It is simpler and more efficient to use a <https://www.mathworks.com/help/matlab/matlab_prog/regular-expressions.html regular ex...

8 years ago | 1

| accepted

Answered
How can I assign user input values to specific rows and columns in a matrix?
Using a table would be much easier. But given the data in your question, you could do this: A = [... 2000 1300 900 ...

8 years ago | 0

| accepted

Answered
How to find where indices equal?
This would be much easier if you worked with logical indices rather than subscripts, because then you could just use |&|, e.g.: ...

8 years ago | 0

Answered
Use Parfor to split a 4D matrix into several 3D matrices
Firstly it is important to note that processing a sequence of |.mat| files is _much_ simpler when the variable names inside eac...

8 years ago | 0

Answered
function file for maclauring series approximation
Without a semi-colon a line of code will print its output: function [approx] =cos1(x,n) %Calculates the Malcurin series ...

8 years ago | 0

| accepted

Answered
issue with a*a
It depends on what you expect to happen: 1. If you expect to multiply each element with itself, then just follow the instruct...

8 years ago | 3

Answered
Issue with saving real and imag values to a text file
You need to explicitly obtain the real and imaginary parts, before printing with |fprintf|: M = [real(grid(:)),imag(grid(:)...

8 years ago | 1

| accepted

Answered
How to vectorize this code to eliminate nested For loops?
Assuming that the first set of loops is supposed to normalize the data: nEnergy = (Energy-min(Energy(:))) / (max(Energy(:))...

8 years ago | 0

| accepted

Answered
Find "intersection" of data array
Download and use |selfintersect|: <https://www.mathworks.com/matlabcentral/fileexchange/13351-fast-and-robust-self-intersecti...

8 years ago | 0

| accepted

Answered
How do you convert numbers to percentages?
>> P = 100 * transMatrix P = 2.00000 1.00000 0.00000 0.00000 6.00000 -8.00000 3.00000 12.0000...

8 years ago | 3

| accepted

Answered
How could I add a zero before the last element in any size vector?
This will work regardless of the vector orientation: >> V = [-5,4,-4,6,8,-3]; >> V(end:end+1) = [0,V(end)] V = -...

8 years ago | 0

Answered
How can I only swap the first and last element of a vector?
Simply in one line: >> V = [-5,4,-4,6,8,-3]; >> V([end,1]) = V([1,end]) V = -3 4 -4 6 8 -5

8 years ago | 0

| accepted

Answered
Output does not get published, error using evalin shows
There seems to be a problem with the name: in MATLAB, function and script names are not permitted to have space characters in th...

8 years ago | 0

| accepted

Answered
how to change multiple elements in a character array at once
Just use indexing: Letters([5,end]) = 'XZ'

8 years ago | 1

| accepted

Answered
Concatenate variables from multiple files to just one single matlab file
This assumes that the files are returned by the OS in the required order (i.e. the filenames use leading zeros), otherwise downl...

8 years ago | 1

| accepted

Answered
Combine multiple matrix variables into a structure?
You do not say anything about how these variables get into the workspace, so I am going to a guess that they are all contained i...

8 years ago | 1

| accepted

Answered
How can i ignore characters while reading a numeric txt file?
Using |importdata| (untested): S = dir(fullfile(IGNfolder,'*.txt')); C = cell(1,numel(S)); for k = 1:numel(S) ...

8 years ago | 1

Answered
Deleting Files in other folders with different names
This should get you started (untested): S = dir('*_data'); N = {S([S.isdir]).name}; for k = 1:numel(N) F = ful...

8 years ago | 0

Answered
Arrays: What does [] do inside an array and is their any other command that serves the same purpose?
_"What does [] do when played inside something like this:"_ min(Distance,[],3) In this case |[]| simply acts as a placeh...

8 years ago | 1

Answered
Code only works sometimes when run
_"any ideas why?"_ Because you test for numbers that do not exist in |A|, and so the output is empty. Lets have a look at ...

8 years ago | 2

| accepted

Answered
How do i create variables from strings for the purpose of writing different variables to text file.
This is trivial when you put those values into *one* small vector. Then you can use indexing very simply: V = [1,2,3]; S...

8 years ago | 0

| accepted

Load more