Answered
How can a change image format like .jpg to .png by using loops and with out use of 'imwrite' command
<https://www.mathworks.com/help/matlab/ref/imwrite.html |imwrite|> does not require any toolboxes (it is standard MATLAB), so wh...

9 years ago | 1

Answered
How to change variables with same name into new ones instead of structure array
Loading that data into a structure is the best way to do this. It might seem complicated, but even as a beginner there is no rea...

9 years ago | 1

Answered
how to join 3 strings into single string?
No ugly and inefficient loop is required: >> C = {'Tcgh','A6','1214'}; >> out = sprintf('-%s',C{:}); >> out(2:end) ...

9 years ago | 0

| accepted

Answered
Extract non zero elements from 2D array
No ugly loops are required: >> [R,C] = find(X) >> out = accumarray(R,X(X~=0),[],@(n){n}); >> out{2} % second row ans =...

9 years ago | 0

| accepted

Answered
2-D Meshgrid Rotation Matrix Multiplication
Firstly you are using the wrong multiplication operator: you need to use <https://www.mathworks.com/help/matlab/ref/mtimes.html ...

9 years ago | 2

| accepted

Answered
''insertAfter'' command does not work
When you read the <https://www.mathworks.com/help/matlab/ref/insertafter.html |insertAfter|> documentation it states in bold let...

9 years ago | 2

| accepted

Answered
How to change current figure handle?
train_image = getimage(handles.axes1)

9 years ago | 1

| accepted

Answered
Using double instead of im2double for images?
_"What is happening here?"_ You input image is of class uint8, which means its values are from [0-255]. When you call |double...

9 years ago | 2

| accepted

Answered
Produce a matrix with the class of its elements
Assuming that the input is a cell array (otherwise this task does not make much sense): >> A = {double(1),single(2);uint8(...

9 years ago | 2

| accepted

Answered
for-loop assignment with several dimensions
The RHS is empty, because the logical index |market_id==i_market & product_id == j_product| is all false for some permutation of...

9 years ago | 1

| accepted

Answered
Print a table with 4 columns fprintf
When you put all of the data into one matrix then your task is easy: >> M = [95, 1, 10.9831, 8.9874;... 2, ...

9 years ago | 0

Answered
how to apply condition on multiple columns?
This can be done very efficiently with just one call to <https://www.mathworks.com/help/matlab/ref/accumarray.html |accumarray|>...

9 years ago | 2

Answered
How to assign array range to variable including the "end"-specifier?
The simplest solution (why waste your time?): beg = 2; B = A(beg:end)

9 years ago | 0

Answered
How to create a set of random numbers
You could use |randperm| to randomly arrange a vector of exactly those numbers: >> vec = [repmat(1,21,1);repmat(2,38,1);rep...

9 years ago | 0

| accepted

Answered
How can I set the range of an array depending on its dimension?
You could wrap <https://www.mathworks.com/help/matlab/ref/subsasgn.html |subsasgn|> in a simple function that generates the req...

9 years ago | 0

| accepted

Answered
Can I store multiple outputs of a function into a cell?
Your syntax was almost correct, you just need to preallocate the output cell array and use square brackets: >> inp = {1:3,4:5,...

9 years ago | 2

Answered
Import Data From Text File and Analyse
The most efficient way to import this data is to use <http://www.mathworks.com/help/matlab/ref/textscan.html |textscan|> by itse...

9 years ago | 3

| accepted

Answered
Creating an array based off column value
Use logical indexing: >> A = randi(3,5,3); >> X = A(A(:,3)==1,:); >> Y = A(A(:,3)==2,:); >> Z = A(A(:,3)==3,:); ...

9 years ago | 0

| accepted

Answered
I want to index across multiple dimensions using a vector, as opposed to comma notation
Lets first create some fake data: >> A = randi(9,4,3,2); % the data >> V = [3,2,1]; % the indices in a vector >> C = ...

9 years ago | 1

Answered
Assigning imported data to variable names (also imported)
If you want to write efficient code that is easy to debug, read my answer below. If you wish to use |eval| to assign values to v...

9 years ago | 1

| accepted

Answered
Using a histogram for cell array of letter grades
Use the third output of <https://www.mathworks.com/help/matlab/ref/unique.html |unique|> to generate numeric values from the cel...

9 years ago | 1

Answered
Adding values in an array within limits
>> A = [1;2;3;3;5;4]; >> B = A.*(cumsum(A)<=9) B = 1 2 3 3 0 0

9 years ago | 1

Answered
FOR loop overwrites values
There are four loops, and only three indices are used: for mm = ... for kk = ... for pp = ... ...

9 years ago | 0

Answered
How to find a first letter in a string?
This is easy with <https://www.mathworks.com/help/matlab/ref/regexp.html |regexp|> or |regexpi|: >> str = '2017-03-28_15505...

9 years ago | 0

Answered
Why is my code skipping numbers?
Your code is not skipping any numbers at all. The <https://www.mathworks.com/help/matlab/ref/hist.html |hist|> documentation cle...

9 years ago | 0

Answered
Cell in cell in cell...... versus multiDimensional cell
Assuming that the subarrays can be joined together in one multi-dimensional array, then the multi-dimensional array is better. S...

9 years ago | 2

| accepted

Answered
how can I fill a matrix with randomly -0.01 and 0.01
>> V = [0.01,-0.01]; >> V(randi(numel(V),5,5)) ans = -0.010000 0.010000 -0.010000 0.010000 0.010000 -0....

9 years ago | 1

| accepted

Answered
I want to create a block matrix using some loop (and logical conditions). I wrote the following code that works when "p" and "q" are numbers. How can I make it work in the same way, when "p" and "q" are matrices?
Here is a simple solution using indexing: >> C = {[2,1;1,2],[0.3,0.2;0.2,0.3],[0,0;0,0]}; >> V = [1,3,2,3,3]; % define y...

9 years ago | 0

Answered
Elements of matrix in matlab
Use <https://www.mathworks.com/help/matlab/ref/transpose.html |transpose|>: >> vec = [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0...

9 years ago | 1

| accepted

Load more