Answered
Beginner MATLAB question (I just started using matlab a week ago)
Simpler and more efficient to use logical indexing: idx = ss(:,1)==1; out = ss(idx,2) If you really want to use |find|: idy ...

7 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?
A = str2double(input('start:','s')); S = str2double(input('step:','s')); X = nan(3,3); for R = 1:3 for C = 1:3 ...

7 years ago | 0

| accepted

Answered
Assigning count values to the column of a matrix
Either one of these, depending on the order that you want: A(:,3) = 1:29 A(:,3) = 29:-1:1

7 years ago | 1

| accepted

Answered
5 outputs of a function, store each output data in 5 arrays from for loops
% parameters: B = 14; L = 14; r = 9; R = 6; % bad idea to use variable names that differ only by case Ach = 231; A...

7 years ago | 0

| accepted

Answered
How to create a colormap attributing specific colour to each element?
A = [1,2,3,4;2,2,3,1;1,1,4,2]; map = [0,0,1;0,0,0;0,1,0;1,1,0]; % [blue;black;green;yellow] imagesc(A,[1,4]) % better to set t...

7 years ago | 0

Answered
Removing a row from a matrix based on certain conditions
You do not explain how you want to handle the 8 columns in your logical comparisons: do you only want to remove the entire row i...

7 years ago | 0

| accepted

Answered
how can I choose random "n" matrices from array of matrices ?
If you followed the advice I gave in response to your last question: https://www.mathworks.com/matlabcentral/answers/441492-how...

7 years ago | 0

Answered
How to remove an entry within a cell of a cell array
cellfun(@(x) x(x>2), C, 'Uni', 0)

7 years ago | 0

| accepted

Answered
for loops and creating new vectors
You don't need any loops, just use ismember: >> mytable = [111,11,1;222,22,2;444,44,4;666,66,6;999,99,9] mytable = 111 ...

7 years ago | 0

| accepted

Answered
Split character arrays at given column
"I want to be able to store all the numbers in a vector ..." That is easy with sscanf: >> vec = sscanf(val.','%f') vec = ...

7 years ago | 0

| accepted

Answered
For loop cycle struct
This is MATLAB, so it is simpler to avoid using a loop: >> S(1).Mass = 200; S(1).Dist=50; >> S(2).Mass = 350; S(2).Dist=100; ...

7 years ago | 0

Answered
how to get the first position in the array and get size array contains matrices
Use a cell array: >> C = {m1,m2,m3,m4}; >> C{1} ans = 0 1 0 0 https://www.mathworks.com/help/matlab/cell-arrays....

7 years ago | 0

Answered
Row Sorting of Matrices
>> A = [0,2,4;0,1,6;0,0,5] A = 0 2 4 0 1 6 0 0 5 >> [~,idx] = sortrows([sum(A==0,2),A]); >> B = A(idx...

7 years ago | 1

| accepted

Answered
Why does this not vectorize
You are overwriting x values with the loop, so when you then try the vectorized code you have different x values. Clearly differ...

7 years ago | 0

Answered
How to save cells of multi-indexed array as cells in another array?
{sweeps.beams}.' Read more: https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://www.mathwork...

7 years ago | 0

| accepted

Answered
Renaming cells inside structure from variable in for loop
You can certainly rename fields dynamically: https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variab...

7 years ago | 1

Answered
write a script that creates identity matrices of any size without using the function eye
Don't use a loop, learn to write simple vectorized code: N = 5; M = zeros(N); M(1:N+1:end) = 1

7 years ago | 1

Answered
How to handle a colormap with multiple patches?
Set the caxis limits: https://www.mathworks.com/help/matlab/ref/caxis.html A simple working example: >> map = [1,0,0;1,0.5,0;...

7 years ago | 0

| accepted

Answered
Next line command in fprintf is not working while writing in text file
fileid = fopen('test.txt','wt') ^ open as a text file. And also stop using awful, outdated, featur...

7 years ago | 2

Answered
How to add a variable that is not shown in workplace to the workplace?
"Sometimes I write some functions but I cant see some of my variables in workplace after I run the code!" That is the expected ...

7 years ago | 0

Answered
another import from textfile question
The main difficulty with your file is that it uses a decimal comma. MATLAB supports only a decimal point. You can search this fo...

7 years ago | 0

| accepted

Answered
Set axes and other properties with only one command
"Ok, but what about the different fontsize for the numbers in the axes, the legend and so on?" Sure. Read the set documentation...

7 years ago | 0

| accepted

Answered
Help with using a switch statement
val = str2double(input('enter number','s')); chr = input('enter letter','s'); switch chr case 's' disp(sin(val))...

7 years ago | 0

| accepted

Answered
question using while loop
v = input('Continue?', 's'); while strcmpi(v,'y') disp(rand) v = input('Continue?', 's'); end When applied to cha...

7 years ago | 0

Answered
How to read out a textfile from a specific line
opt = {'Delimiter','\t', 'CollectOutput',true}; [fid,msg] = fopen('pG8.txt','rt'); assert(fid>=3,msg) % Ignore lines until "D...

7 years ago | 1

| accepted

Answered
match values of cells to numbers
% Fake data: C = cell(6,6); C(:,1) = {'A'}; C([1,6],2) = {'B'}; C(6,3) = {'C'}; C(5,2) = {'D'}; V = {'A','B','C','D','E'};...

7 years ago | 0

| accepted

Answered
How to call a function from outside itself ?
"why does this happen?" Because local functions are only callable within the same file. This is explained in the documentation:...

7 years ago | 0

| accepted

Answered
how i can get a filename from an image proviously defined
fnm = '100126_122731 tamp1.jpg'; a = imread(fnm); b = rgb2gray(a); imshow(b) dct2(fnm,10,10)

7 years ago | 0

Answered
How to delete elements from structure
Deleting an element of a structure is easy, and it has nothing to do with fields: S.population(1).type = 1; S.population(2).ty...

7 years ago | 1

| accepted

Answered
Sort elements of an array with a given a priority, keeping track of indexes (includes repeated elements)
>> vR = [1.5,2,1.25,3,3.5,5,8,2.359,3] vR = 1.5000 2.0000 1.2500 3.0000 3.5000 5.0000 8.0000 2.3590 3.000...

7 years ago | 2

Load more