Answered
How to pad all numbers in array ?
b = sprintf(' %06d',a{:}); ^ add this space

10 years ago | 1

| accepted

Answered
Storing results of nested loops in one matrix
Simply <https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html preallocate> an output array of the correct ...

10 years ago | 1

| accepted

Answered
Hello ! I am new to MATLAB, and i need a small help in using it ..
Hello Sunnil KR, Welcome to MATLAB Answers! While it is possible to do what you are asking, it would be a slow and buggy way ...

10 years ago | 1

Answered
How to read excel files in desired sequence from a folder?
Use my FEX submission, which I wrote to solve exactly the problem that you have: https://www.mathworks.com/matlabcentral/fileex...

10 years ago | 0

| accepted

Answered
hello how to create this matrix with specific diagonals?
Use <https://www.mathworks.com/help/matlab/ref/toeplitz.html |toeplitz|>: >> n = 5; >> toeplitz([2,-1,zeros(1,n-2)]) ...

10 years ago | 0

| accepted

Answered
How to interpolate gridded matrix to a non-gridded one?
Because your data points in |B| are gridded you can simply use any of the <https://www.mathworks.com/help/matlab/grid-based-inte...

10 years ago | 0

| accepted

Answered
How to request additional data from the user in a function
Something like this: function out = year2016(m) VN = datenum([2016,m,1]):datenum([2016,m+1,1])-1; DN = 1+mod(VN-3,7);...

10 years ago | 0

| accepted

Answered
How can I create a random matrix with no duplicate value in the line
Use <https://www.mathworks.com/help/matlab/ref/randperm.html |randperm|> to get a sequence of integers with no repetitions: ...

10 years ago | 1

| accepted

Answered
How can I convert a string to a text file
You can read about all file import and export functions here: <https://www.mathworks.com/help/matlab/data-import-and-export.h...

10 years ago | 0

Answered
Concatenate and extract elements of cell array to a non-cell array
A simple solution: >> A = {[1 3],[],[2,3,7,8];[2,4,5,7],[4,7,8],[];[],[],[]}; >> B = [13,0,2378;2457,478,0;0,0,0] ࣳB ...

10 years ago | 0

Answered
Eliminating common elements across multiple arrays
This is easy using <https://www.mathworks.com/help/matlab/ref/intersect.html |intersect|> and some basic MATLAB indexing: ...

10 years ago | 0

Answered
write in text file
One fast solution is to not use a loop: str = dec2hex(randi([0,15],1,5000)); fmt = repmat(sprintf('%s\t',repmat('%c',1,8...

10 years ago | 0

Answered
How to code "if (a and b) or (c and d)"
This does not do what you want (because you are not comparing |x| with anything, so MATLAB treats the |x| as |true| if it is non...

10 years ago | 1

| accepted

Answered
Adding tick marks without overriding existing marks
Play around with this: >> x = 5.7; >> yV = get(gca,'ylim'); >> text(x,yV(1),num2str(x),'VerticalAlignment','top','Hor...

10 years ago | 0

| accepted

Answered
for r=1:mrow d1=data(r,:);cluster=c(r,1); p=['Data object ', d1 , 'is belonging ', cluster, 'Clusters']; disp(p); end
Use <https://www.mathworks.com/help/matlab/ref/fprintf.html |fprintf|>: >> fprintf('%s is %d years old\n','Pavan',26) Pava...

10 years ago | 0

| accepted

Answered
Setting requirements for matrix and vector inputs into function and generating error message
I would recommend using <https://www.mathworks.com/help/matlab/ref/assert.html |assert|> to check the input arguments: funct...

10 years ago | 0

Answered
Problem plotting sinc function.
There is no problem with your function, however you only calculated eleven data points (check the length of |x|), which gives a ...

10 years ago | 0

| accepted

Answered
How can I create vector for values in the range -π < θ < π ?
Use <https://www.mathworks.com/help/matlab/ref/colon.html |colon|> notation, e.g.: T = -pi:0.01:pi This kind of very basi...

10 years ago | 3

Answered
Adding a number to all existing values within a column
This should get you started: >> mat = rand(80000,4); >> mat(:,2) = mat(:,2) + 14; <https://www.mathworks.com/matlabce...

10 years ago | 0

Answered
I'm getting two answer from my function, I only want one. How do I fix this?
Your code omly returns one variable, |payment|, but it will print several other variables to the command window because you did ...

10 years ago | 0

Answered
how can i extend a matrix with columns of random entries under the condition that the 3 randomn numbers in column 1-3 sum up to 1?
Based on this code: <http://stackoverflow.com/questions/8064629/random-numbers-that-add-to-100-matlab/8068956> you can try...

10 years ago | 1

Answered
How do I create a matrix with a sine and cosine function?
Use basic <https://www.mathworks.com/help/matlab/ref/mtimes.html matrix multiplication>: >> V = 1:10; >> B = sin(V.')*co...

10 years ago | 0

| accepted

Answered
Possibilities to read out cell arrays and properties efficiently
If the objects are structures, then the most efficient way is to store your data in a <https://www.mathworks.com/help/matlab/mat...

10 years ago | 0

| accepted

Answered
avoid zero value from vector
Simply use logical indexing: >> x =[5 0 9 0 4 0 7 0]; >> xnew = x(x~=0) xnew = 5 9 4 7

10 years ago | 0

| accepted

Answered
How to display the selected function from a switch case statement
You can use <https://www.mathworks.com/help/matlab/ref/func2str.html |func2str|>: >> fun = @(x,y) sqrt(x) + sin(y); >> s...

10 years ago | 0

Answered
How can I implement different structs in a cell
Simple: dataset = rand(3); N = 5; signal = cell(1,N); for k = 1:N signal{k} = dataset; end

10 years ago | 0

| accepted

Answered
Is Clearing Redundant Cells Necessary
Scripts use the caller's workspace, and do not "clear" anything from memory unless this is explicitly written in the script. The...

10 years ago | 1

Answered
Copy certain number from one matrix to another
This does the job perfectly, without any explicit loop: A = [1:12;1,1,1,2,2,2,1,1,2,2,2,1]' idx = A(:,2)==2 & [true;diff...

10 years ago | 0

| accepted

Answered
Not enough input argument frenzy.
When you type opt_compute_posterior(plJoint, 0, 300, 1000) you are calling |plJoint|, but with no input arguments, thus t...

10 years ago | 0

| accepted

Answered
Extracting data from 2 column array based on infromation in the 1st colum
The best solution is to use <https://www.mathworks.com/help/matlab/ref/accumarray.html |accumarray|>: >> A = [1,36;1,24;1,2...

10 years ago | 1

| accepted

Load more