Answered
How do I add an additional column to a cell array based on existing values in another column?
>> x = {'x1',1';'x2',2;'x3',1} x = 'x1' [1] 'x2' [2] 'x3' [1] >> x(:,3) = {0}; >> x([x{:,2}]==1,3) =...

7 years ago | 0

Answered
Why doesn't legend distinguish colors?
The problem occurs on this line: plot(t,ca,'r') Because t is a vector (with 501 elements) and ca is a scalar, then you are tel...

7 years ago | 0

| accepted

Answered
Building the Fibonacci using recursive
I doubt that a recursive function is a very efficient approach for this task, but here is one anyway: function v = myfib(n,v) ...

7 years ago | 1

Answered
How do I multiply an integer with a single value from the matrix?
You need to convert the character vector (contained in the output) into numeric, e.g.: C = inputdlg(...); % C is a cell array o...

7 years ago | 0

| accepted

Answered
When using the eval function, MATLAB doesn't recognize " , " as an ASCII character, rendering it useless
Evil eval strikes again! This is a very good example of how using eval results in slow, complex code that is buggy and hard to ...

7 years ago | 2

Answered
showing a colored matrix with colormap
imshow(nwmat,'DisplayRange',[],'Colormap',jet(64))

7 years ago | 0

| accepted

Answered
Nested Functions versus Global Variables
"Why are nested functions better for sharing variables between workspaces than global variables?" Nested functions provide much...

7 years ago | 3

| accepted

Answered
Can anyone please explain me this line of a code?
If audR is a matrix, then audR(audR(:,1)==x,2)==2 % ^^^^^^^^^ % first column of audR % ^^^ % ...

7 years ago | 3

| accepted

Answered
How can I get cell2struct to work within my for loop? "error using cell2struct, Number of field names must match number of fields in new structure"
Following the cell2struct documentation, if fields is a four-element cell array and dim is 1 then temp would have to be a cell a...

7 years ago | 0

Answered
How to find image size without imread and size(*,1)
Use imfinfo: info = imfinfo(...); info.Height info.Width

7 years ago | 3

| accepted

Answered
How to repeat a 4d vector for n times
Z = repmat(W,1,1,1,10)

7 years ago | 0

| accepted

Answered
Is this a bug? And if not, why it is defined like that
"Is this a bug?" Not according to the MATLAB documentation: https://www.mathworks.com/help/matlab/matlab_prog/command-vs-funct...

7 years ago | 3

Answered
Loading multiple (e.g. ~ 3000) mat files into workspace and merging them in a table
" i will need to list all 3000 variables from workspace.." That is a good example of why load-ing directly into the workspace i...

7 years ago | 1

| accepted

Answered
Conversion to logical from struct is not possible. (It's a binary matrix!)
As the load documentation clearly states, if the file is a .mat file then the output of load is a scalar structure, whos fields ...

7 years ago | 1

| accepted

Answered
Summation of Series of Variables
@(x) sum(x) or simply: @sum

7 years ago | 0

Answered
Find Optimal Arrangement for Elements
I recently solved a very similar problem in my FEX submission maxdistcolor: https://www.mathworks.com/matlabcentral/fileexchang...

7 years ago | 0

Answered
How to convert a cell array containing various inline functions to a unique inline function?
You could hide the loop inside cellfun: >> a = rand(3,3); >> C = {@(x)(a(1,1)-x)^2,@(x)(a(2,2)-x)^2,@(x)(a(3,3)-x)^2}; >> F =...

7 years ago | 1

| accepted

Answered
Problem of using "assignin" during figure callbacks
You just need to add waitfor to your code: function out = test(...) out = []; fgh = figure(...); ... function mycallbac...

7 years ago | 0

| accepted

Answered
Get Column Name if matrix row value is 1
First download Jos's excellent runindex: https://www.mathworks.com/matlabcentral/fileexchange/56131-runindex Data: L = {'A','...

7 years ago | 0

| accepted

Answered
how to split data
Why not just use basic MATLAB indexing?: >> x = rx(1:5) x = 1 3 4 5 6 >> y = rx(6:10) y = 7 8 ...

7 years ago | 0

Answered
sort 2 matrices for minimum numbers sum and divide them
This is MATLAB, so don't waste your time writing inefficient loops. Learn to write simpler vectorized code, just like experienc...

7 years ago | 2

| accepted

Answered
Acces data in nested structure
"Any idea to acces the data without a loop?" Not really. You can either use an explicit for loop or an implicit loop using arr...

7 years ago | 1

| accepted

Answered
How to find the same multiple elements in two different matrices
Do NOT use ismember! Because of the floating-point numbers you should use ismembertol: >> [idx,idy] = ismembertol(B(:,1:3),A(:,...

7 years ago | 0

Answered
variables are not saved in workspace after function.
You need to explicitly pass those variables between workspaces, exactly as the MATLAB documentation describes: https://www.math...

7 years ago | 0

Answered
Printing iterations in while loop
Your second fprintf simply prints four newlines, and ignores its inputs. As the fprintf documentation shows, you need to include...

7 years ago | 1

Answered
Searching for rows of cell arrays containing strings in a different cell array having a collection of multiple other strings
This is not a very beautiful solution, nor might it be suitable for such large cell arrays: >> A = {'ABCS' '100'; 'A' '10'; 'C'...

7 years ago | 0

| accepted

Answered
How to avoid duplicate struct fields when loading structs
It appears that the variables inside the .mat files were unfortunately also named using the dates, rather than simply using one ...

7 years ago | 1

| accepted

Answered
Error using patch Vectors must be the same lengths.
The problem is very simple: you never actually convert the string data to numeric. Replace all of your Z definitions with this:...

7 years ago | 0

| accepted

Answered
Matlab sorting matrix with index (smallest to biggest)
Get rid of the loop: [sortedDist,idx] = sort(Location,'ascend')

7 years ago | 3

| accepted

Answered
Assigning a 2D matrix
Simpler without a loop: >> [X,Y] = ndgrid(1:3,1:5); >> M = [X(:),Y(:)] M = 1 1 2 1 3 1 1 2 2 2 ...

7 years ago | 0

Load more