Answered
Geometric series that halves but prints first 10 elements i.e. 1/2,1/4....,1/1028
Much neater than using a loop: >> 1./pow2(1:10) ans = 0.5000 0.2500 0.1250 0.0625 0.0313 0.0156 0...

11 years ago | 0

Answered
how to sort an array based on a specific column and display it in another array
[~,idx] = sort(sector1(:,end)); and use the index variable |idx| to sort whichever other variables you wish to.

11 years ago | 0

Answered
min function why do results change for numbers with decimal values?
When you compare <https://en.wikipedia.org/wiki/Floating_point floating point numbers> (such as using |==| or |unique|) you shou...

11 years ago | 0

Answered
Resizing a vector to a matrix
It depends on _how_ you want to resize the vector. If you simply want to _replicate_ those values into every row of the final ma...

11 years ago | 0

Answered
Function to take grid reference
>> fun = @(s)[upper(s(1))-64,str2num(s(2:end))]; >> fun('A10') ans = 1 10 >> fun('C4') ans = 3 4 ...

11 years ago | 0

| accepted

Answered
Use Matlab to select specific nonzero values in cell array
Try this: X = {0,'A','B','C'; 'A',0, 5, 6; 'B',1, 0, 2; 'C',3, 4, 0}; % Y = X(2:end,2:end)...

11 years ago | 0

Answered
How to change the colors in colormap function
Identical R, G and B values gives gray, and this is what you are defining in your variable |cmap|. If you want _colors_ then ...

11 years ago | 1

Answered
Reshape dataset with time intervals?
You can use <http://www.mathworks.com/help/matlab/ref/histc.html |histc|> (or <http://www.mathworks.com/help/matlab/ref/histcoun...

11 years ago | 0

| accepted

Answered
How can I convert a number into a text string for their corresponding word in english ?
Very easily using my FEX submission |num2words|: <http://www.mathworks.com/matlabcentral/fileexchange/47221-number-to-words> ...

11 years ago | 0

| accepted

Answered
how to replace the matrix by arrayfun() for the matrix like this?
Your explanation is not entirely clear, and it would be useful to have a *complete* output example. Although you write that _"I ...

11 years ago | 0

| accepted

Answered
Getting error when i am running my code........plz help me.
You are going to have to learn how to use the <http://www.mathworks.com/help/matlab/debugging-code.html *debugging tools*>. This...

11 years ago | 0

Answered
if statement returns false to checking if 0.05 +0.01 = 0.06
This is the comparison you are trying: >> (0.05+0.01) == 0.06 ans = 0 But when you compare <https://en.wikipe...

11 years ago | 1

| accepted

Answered
Briefly explain two main differences between writing MATLAB code as a user-defined function compared with just writing a script file?
Scripts are just a collection of commands, whereas: # Functions each have their own workspace. # Functions can have input an...

11 years ago | 1

Answered
Get rid of unwanted output
That |30| is the output of <http://www.mathworks.com/help/matlab/ref/fprintf.html |fprintf|>, exactly as you have coded it. The ...

11 years ago | 1

| accepted

Answered
Help with If else statements
Your first |elseif| is always going to be true. Why? Because you are ignoring <http://www.mathworks.com/help/matlab/matlab_prog/...

11 years ago | 0

| accepted

Answered
Trasform to cell of strings
I already answered this in <http://www.mathworks.com/matlabcentral/answers/258225-how-to-transform-a-cell-array-of-cells-in-a-ma...

11 years ago | 1

| accepted

Answered
How can I make a method that takes a String and prints it out in AltCase meaning that the first letter is uppercase and each subsequent character alternates between lowercase and uppercase.
>> str = 'hello world!'; >> str(1:2:end) = upper(str(1:2:end)); >> str(2:2:end) = lower(str(2:2:end)) str = HeLlO WoR...

11 years ago | 0

Answered
How cam I write a method that takes in a String and returns a new string that replaces every vowel with two occurrences of that vowel.
>> str = 'hello world!'; >> regexprep(str,'([aeiou])','$1$1') ans = heelloo woorld!

11 years ago | 0

Answered
How can I write a method that will check if the letters in a string are all the same?
Using |diff| would be much faster than |unique|: >> str = 'aba'; >> any(diff(+str)) ans = 1 >> str = 'aaa'; >>...

11 years ago | 0

Answered
Error : Undefined function or variable 'I'
Stop using |assignin| for trivial passing of variables. When you pass variables properly and don't just "poof" them into existen...

11 years ago | 1

Answered
Write MATLAB code to create and print a vector GS that stores the first 10 terms of the geometric sequence that halves each time: {1/2, 1/4, 1/8, 1/16, ... 1/1024 }
>> 1./pow2(1:10) ans = 0.5 0.25 0.125 0.0625 0.03125 0.015625 0.0078125 0.0039062 0.0019531 0.00097656

11 years ago | 0

Answered
Merge two columns into one column?
>> A = [123,321,20001130]; >> B = [456,654,32378]; >> F = @(n)arrayfun(@int2str,n,'UniformOutput',false); >> cellfun(...

11 years ago | 0

Answered
possible bug in "unique" function
There is no bug. You need to learn about the practical limits of <https://en.wikipedia.org/wiki/Floating_point floating point nu...

11 years ago | 0

Answered
Bug Report: "Different answers for two same statements"
There is no bug. You need to learn about the practical limits of <https://en.wikipedia.org/wiki/Floating_point floating point nu...

11 years ago | 1

Answered
Sort cell array based on 2 columns with date and time (strings)
This is _trivial_ if <https://en.wikipedia.org/wiki/ISO_8601 *ISO 8601*> date strings are used, because then a lexicographical s...

11 years ago | 0

Answered
Create a Matrix with a specific main diagonal
One very simple solution: >> X = +~eye(4); >> X(X==0) = 5 X = 5 1 1 1 1 5 1 1...

11 years ago | 0

Answered
3>2>1 returns logical 0?
The basic problem is that you are attempting *two* <http://www.mathworks.com/help/matlab/ref/relationaloperators.html logical re...

11 years ago | 1

| accepted

Answered
How to transform a cell array of cells in a matrix
>> X = {{'A'},{'bb'};{'CCC'},{'d'}} X = {1x1 cell} {1x1 cell} {1x1 cell} {1x1 cell} >> Y = reshape(...

11 years ago | 0

Answered
How to obtain all possible combinations from n (large) arrays that sum up to a number
It seems that you want the <https://en.wikipedia.org/wiki/Cartesian_product Cartesian product> of those vectors, but with some e...

11 years ago | 0

Answered
How can I count the followed occurrences of each element in a vector in MATLAB?
Judicious use of <http://www.mathworks.com/help/matlab/ref/diff.html |diff|> solves this easily: x = [1 1 1 2 2 1 1 2 5 5];...

11 years ago | 0

| accepted

Load more