How to fill remaining dates of the month based on specific date - date

I try to write vba code. I have 01–07-2022 at cell B12. I want to fill the remaining days of the month from cell B13 to B41 or B40.
I try
For each cell in range (b13:b42)
If cell =0, then cell= b12+1
Next cell
It is not working.
Could anyone help on it?
Thx joe

Related

Using cellfun for logical indexing

I have a cell data containing one row and four column. What i am trying to do is to go through elements in first column and see if an year '2018' is seen in the first column of each cell. When i perform this code, it will only give me the indices containing '2018' in the fourth cell. Not all the cells. Any help will be appreciated.
time = cellfun(#x, contains(x,'2018'),data{ii}(:,1))
I have created a small data sample as part of an example which I hope will help you solve the problem.
%Create cell array of strings.
data = {["2018","date","2018";"stack","cell2018","fun"],["data","stackoverflow","2018";"array","variable","data2018"]}
%Search for substring 2018 in the first column of every cell.
time = cellfun(#(x) contains(x(:,1),'2018'),data,'UniformOutput',0)
The output of time is a logical cell array:
>>time
{2×1 logical} {2×1 logical}
>>time{1}
1
0
>>time{2}
0
0
For the first cell, the column contains 2018 and stack, therefore 1 and 0 are returned.
For the second cell, the column contains data and array, therefore 0 and 0 are returned.
If you wish to find the indexes from the logical array, you can use the find function with outputs [row,col].

Write a cell array in text file using Matlab

I have a cell array with the size of 1*15.
whos C
Name Size Bytes Class Attributes
C 1x15 222520 cell
In each cell, there are 1170 elements. The 15 cells are mixture of strings and numbers. I want to save all these elements to a text file with coma as delimiter.
I tried to use the function dlmcell, dlmcell('file_out.txt.,C,'delimiter',','), it can only write the first value of each cell to the text file. And the cell contains string cannot be write to the text file.
Can anyone help? Thanks!
I just found in http://cn.mathworks.com/help/matlab/import_export/write-to-delimited-data-files.html
write cell data using fprintf.
May help!
[nrows,ncols] = size(C);
for row = 1:nrows
fprintf(fileID,formatSpec,C{row,:});
end

Specific Time range in Matlab

I have a time series xlsx data which has columns like the following one. I would like to get the row data that are in between 8:00:00 AM to 10:00:00 AM for my analysis. Can any one help me out?
Add Velocity Time
0.128835374 10.34912454 8:44:23 AM
0.20423977 8.078739988 8:47:01 AM
0.110629502 13.4081172 9:19:46 AM
0.088979639 5.057336749 9:24:02 AM
0.128835374 10.60785265 10:21:29 AM
0.20423977 9.46599837 10:23:06 AM
[num, txt] = xlsread('Consective_result.xlsx');
T = num(:,3);
TimeVector = datevec(T)
You almost have it right. Use the third column of your txt cell array, and skip over the first row so you don't get the time header. I'm going to assume that your times are entered in as text. Once you do this, just use datenum and determine those times that are later than 8:00 AM and less than 10:00 AM. datenum can conveniently take in a cell array of strings, and it will output a numeric vector where each time string in your cell array is converted into its corresponding numerical representation.
Once you find those rows, you can filter out the rows in each of num and txt using what we just talked about before you continue. Therefore:
[num, txt] = xlsread('Consective_result.xlsx');
times = txt(2:end,3); %// Get the 3rd column, skip 1st row
time_nums = datenum(times); %// Get the numerical representation of the times
%// Figure out those rows that are between 8:00 AM and 10:00 AM
times_to_choose = time_nums >= datenum('08:00:00AM') & time_nums <= datenum('10:00:00AM');
%// Remove those rows then continue
num(1 + times_to_choose) = [];
txt(1 + times_to_choose) = [];
Take special care that I added a 1 to the indices because we omitted the time header in your spreadsheet. Now, num and txt should only contain those times that are between 8:00 AM and 10:00 AM.

Manipulating cells and nested cells

I have P being a 17x1 cell, each cell representing a subject. Each of the 17 cells within P is a 3x1 cell, representing contrast images for each subject. So basically there are 17 subjects, 3 contrast images per subject. So to index the 3rd contrast images of the 14th subject, I would do P{14,1}{3,1}. However, I would like to turn P into 3*17 x 1 cell (or 51x1 cell) instead. This means there are no nested cells within each cell in P. So P would be something like this:
Subject1/contrast1.img
Subject1/contrast2.img
Subject1/contrast3.img
Subject2/contrast1.img
Subject2/contrast2.img
Subject3/contrast3.img
...
Subject17/contrast3.img
Could anyone tell me how this may be accomplished?
How about a oneliner?
a = {{1;2};{3;4};{5;6};{7;8}}
b = vertcat(a{:})

Cell Array: show content and print name cell UITABLE

It is a basic problem but I am not so much experienced in Matlab(Guide).
What I have now is a cell array called Z with 21x2 elements: 21 rows 2 columns.
What I would like to do is to get only the first column (to show only 21x1).
Then, in this column there is a list of names. Inside the 21 rows of this cell there are repeated names. I would like to run through each row of this 21x1 column, detect which are repeated. The repeated ones should be printed in the uitable in a white colour.
Any ideas?
I believe this should deal with the core of your question:
A={'abc' 6;'de' 7;'abc' 8};
[C, ia] = unique(A(:,1));
idx = setdiff(1:size(A,1),ia);
A(idx,1)
This code will list all duplicates.