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

8 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;...

8 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...

8 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 ...

8 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...

8 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...

8 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))...

8 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...

8 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...

8 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'};...

8 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:...

8 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)

8 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...

8 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...

8 years ago | 2

Answered
Plotting struct with out first line
>> X = [s(2:end).a]; >> Y = [s(2:end).b]; >> plot(X,Y) >> xlabel(s(1).a) >> ylabel(s(1).b) Read these to know more: http...

8 years ago | 1

| accepted

Answered
get the index of the n one in a binary vector
>> bv=[0,0,0,0,1,0,0,1,1,1,0,0,1,0,1]; >> idx = find(bv); >> idx(4) ans = 10

8 years ago | 0

Answered
How to structure input data as what I need?
str = fileread('store.txt'); str = strtrim(str); C = regexp(str,'\s*,\s*','split'); [fid,msg] = fopen('store2.txt','wt'); as...

8 years ago | 1

| accepted

Answered
nargin doesn't work with my settings
"nargin doesn't work" nargin does work. MATLAB input arguments are (for better or for worse) entirely positional. Inputs are n...

8 years ago | 1

| accepted

Answered
Plotting n-by-m matrix
Good question. I also faced this issue a few years ago, and I found the simplest solution was to append NaN onto the bottom of t...

8 years ago | 0

| accepted

Answered
Add a zero element to the beginning of each existing cell array
cellfun(@(v)[0;v],C,'uni',0) And checking: >> C = {[-8;-5],[1;-4;-5;-5;-5],[-3;-5]}; >> CC = cellfun(@(v)[0;v],C,'uni',0); >...

8 years ago | 2

| accepted

Answered
I am having a error using fprintf
You should always return the second output of fopen and check the f_id value: [f_id,msg] = fopen(txt_name,'wt'); assert(f_id>=...

8 years ago | 0

| accepted

Answered
folder split into parts
In two lines: movefile('Prostatex0000_*.nii','subdir0') movefile('Prostatex0001_*.nii','subdir1')

8 years ago | 0

| accepted

Answered
How to store the result of a loop in a cell?
Your code is only iterating once, because for i = 1:44 ^^ you forgot this. PS: I would recomend using ii or k as the ...

8 years ago | 0

| accepted

Answered
Flipping specific segment of string rather than the whole string
regexprep(str,'\w+','${fliplr($0)}')

8 years ago | 2

Answered
I am getting an error as "Operands to the || and && operators must be convertible to logical scalar values. Error in xd (line 8) if (t>=t1)&&(t<t2)".
Learn to use logical indexing https://www.mathworks.com/help/matlab/getting-started-with-matlab.html Logical indexing is a ver...

8 years ago | 1

Answered
Reading a number from text file
>> str = fileread('MASS.txt'); >> tmp = regexp(str,'(?<=X\s+)\d+\.?\d*E[-+]\d+','match','once'); >> str2double(tmp) ans = 3....

8 years ago | 0

| accepted

Answered
choose row cell of matrix
A general solution in one line: C = cellfun(@(r)A(r,:),B,'uni',0)

8 years ago | 0

| accepted

Answered
How to plot an empty 2-D cartesian grid on its own ?
>> axes() >> xlim([200,455]) >> ylim([50,305]) >> grid on >> grid minor Or alternatively in one axes call: axes('XLim',[20...

8 years ago | 3

Answered
How can I convert matrix in cell array to same size cell array within the original array without for loop?
Where C is your 4x1 cell array: D = cellfun(@num2cell,C,'uni',0)

8 years ago | 0

| accepted

Answered
how to flip a general square matrix ( it could have even or odd number of rows/cols ) from it's center in matlab ?
>> M = [1,2,3,4,5;2,6,7,9,10;3,7,11,12,13;4,9,12,16,20;8,10,13,20,25] M = 1 2 3 4 5 2 6 7 9 10...

8 years ago | 0

| accepted

Load more