I'm extremely new to Matlab. Sorry if it's a simple question..
I'm trying to write a loop to add new rows.
files = dir('*.mat');
for ii=1:numel(files)
file = files(ii);
Variable = str;
Correlation = RCDvsMOVRAW;
Signification = pRCDvsMOVRAW;
Lag = lagDiff;
T = table(Correlation,Signification,Lag,'RowNames',Variable);
end
Thank you so much in advance.
Maybe this is what you're looking for:
files = dir('*.mat');
for K=1:numel(files)
file = files(K);
mat = load(file.name);
Variable = {mat.str};
Correlation = mat.RCDvsMOVRAW;
Signification = mat.pRCDvsMOVRAW;
Lag = mat.lagDiff;
T2(K,:) = table(Variable,Correlation,Signification,Lag);
end
writetable(T2)
Hope this helps
Related
I am trying in the code below to generate a report with side by side two images and a splited table but I get an error. Why this error occur?
Code:
close all;
clear all;
clc;
import mlreportgen.report.*
import mlreportgen.dom.*
import mlreportgen.utils.*
Name = {'A';'B';'C';'D';'E';'A';'B';'C';'D';'E'};
codeA = [8;3;8;0;4;8;3;8;0;4];
Height = [1;8;4;7;8;8;3;1;0;4];
Weight = [6;2;1;4;5;8;3;1;1;4];
T = table(Name,codeA,Height,Weight,codeA,Height,Weight,codeA,Height,Weight);
Image1 = Image(which('coins.png'));
Image2 = Image(which('sevilla.jpg'));
rpt = Report("myPDF","pdf");
imgStyle = {ScaleToFit(true)};
Image2.Style = imgStyle;
Image1.Style = imgStyle;
lot = Table({Image2, ' ', Image1});
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
lot.entry(1,2).Style = {Width('.2in'), Height('3in')};
lot.entry(1,3).Style = {Width('3.2in'), Height('3in')};
lot.Style = {ResizeToFitContents(false), Width('100%')};
add(rpt, lot);
chapter = Chapter("Title",'Table Report');
table = FormalTable(T);
table.Border = 'Solid';
table.RowSep = 'Solid';
table.ColSep = 'Solid';
para = Paragraph(['The table is sliced into two tables, '...
'with the first column repeating in each table.']);
para.Style = {OuterMargin('0in','0in','0in','12pt')};
para.FontSize = '14pt';
add(chapter,para)
slicer = TableSlicer("Table",table,"MaxCols",5,"RepeatCols",1);
totcols = slicer.MaxCols - slicer.RepeatCols;
slices = slicer.slice();
for slice=slices
str = sprintf('%d repeating column and up to %d more columns',...
slicer.RepeatCols,totcols);
para = Paragraph(str);
para.Bold = true;
add(chapter,para)
add(chapter,slice.Table)
end
add(rpt,chapter)
close(rpt)
rptview(rpt)
Error:
*Index exceeds the number of array elements. Index must not exceed 10.
Error in try1 (line 26)
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};*
You define the variable
Height = [1;8;4;7;8;8;3;1;0;4];
Then you try and use the report gen function Height
lot.entry(1,1).Style = {Width('3.2in'), Height('3in')};
Because you've shadowed the Height function with a variable, MATLAB is trying to get the element of this array at index '3in', which is either nonsensical or (via some implicit ASCII conversion) is way out of range.
Per my comment on your previous question, I think the way the documentation suggests the report gen functions are imported is bad practice. By using import mlreportgen.dom.* you are putting all of the nicely name-spaced functions from that package into the common area, and in this case it has caused an unclear clash between two things. So there are two options:
Use the namespaced version of Height (and Width), if you did this with all of the report gen functions you would not need the import. The nice side-effect is you get tab-completion when typing the various functions from this package
lot.entry(1,1).Style = {mlreportgen.dom.Width('3.2in'), mlreportgen.dom.Height('3in')};
Sure, you code is longer, but it is more explicit.
... or ...
Simply don't define a variable called Height. Rename this and everything else can stay the same.
I know that X.(Y+Z) = X.Y+X.Z but does X.(Y.Z) = (X.Y).(X.Z) is true?
Please give me help.
Yes it is. X.(Y.Z) = (X.Y).(X.Z). Because X.X=X, one X on the RHS can be removed and we end up with the LHS.
(X.Y).(X.Z) = (X.X).(Y.Z) = (X).(Y.Z) = X.(Y.Z)
You can draw a truth table and verify it yourself.
I'm working on an Apps Script project for Sheets and I don't know if it's because I just never really worked with Sheets or Excel, but I don't know how to set a formula for a whole column through code.
var cell = sheet.getRange([i], 2);
var cell2 = sheet.getRange([i], 1);
var inhoud = cell2.getValue();
cell.setFormula("=(" + inhoud/86400000 + "DATE(1970,1,1)");
I want every B of a row to do something with the A of that same row. In the sheet self it's easy to just "drag the function down", to make it apply to every row, but I don't know how to get that to work in code as I can't use A2, for example, or A2:A30. Part of the problem may be that it's in a for loop:
var subsie = [];
for (i = 0; i < subscriptions.length; i++) {
var subscription = subscriptions[i];
creationdate = subscription.creationTime;
if (subscription.plan.planName == 'ANNUAL' && subscription.renewalSettings.renewalType == 'AUTO_RENEW') {
subsie.push([creationdate, ' ', subscription.plan.planName]);
Logger.log(subsie);
var cell = sheet.getRange([i], 2);
var cell2 = sheet.getRange([i], 1);
var inhoud = cell2.getValue();
cell.setFormula("=(A1:A100/86400000) + DATE(1970,1,1)");
} }
sheet.getRange(sheet.getLastRow()+1, 1, subsie.length, subsie[0].length).setValues(subsie);
The actual goal is to convert the epoch values of A into dates, which I tried in a lot of different ways but turned out to be more difficult than I expected. This was the only formula that seemed to work for my output, which was like this: 1433235478178. How can I make this code work? Thanks in advance!
Solved it :)
creationdate = (subscription.creationTime/86400000)+25567;
I have a question about how can I do something. I have a folder with different images (each image has 3 bands). For example.
Img_244_234_1_1.tif
Img_244_234_1_2.tif
Img_250_234_1_1.tif
Img_250_234_1_2.tif
What I need to do is to mosaic the images by name (for example, all the number 244, 250...). Now, I'm doing it manually in that way:
image1 = imread('C:\Prueba\Img_244_234_1_1.tif','tif');
image2 = imread('C:\Prueba\Img_244_234_1_2.tif','tif');
image3 = imread('C:\Prueba\Img_250_234_1_1.tif','tif');
image4 = imread('C:\Prueba\Img_250_234_1_2.tif','tif');
image_result1 = cat(2,image1,image2);
image_result1 = cat(2,image1,image2);
How can I automatize using the date number (244,250...) which always it's in the same output name position?
Really appreciate any suggestion.
You can use loops (like for x=[244,255]) and the concatenation of strings: ['C:\Prueba\Img_' x '_234_1_1.tif'] will evaluate to `'C:\Prueba\Img_244_234_1_1.tif' if x was 244.
If your file name is well organized, then the following code should work.
cd('C:\Prueba\');
files = dir('*.tif');
for i=1:2:numel(files)
image1 = imread(files(i).name);
image2 = imread(files(i+1).name);
image_result = cat(2,image1,image2);
end
Suppose I have numerous number of outputs and I want them to show as follow
Friction factor = xxx
Load factor = xxx
Thermal factor = xxxx
Is there any way to make the equal sign '=' align to each other? I've tried using the 'fprintf' function with '\t'. However, it's tough for me to achieve such arrangement.
Sincerely thank you for all the helps.
You could do the following:
names = {'Friction Factor','Load Factor','Thermal Factor'};
values = [xx,yy,zz];
nameLength = cellfun(#numel,names);
format = sprintf('%%-%is = %%f\\n',max(nameLength));
for n = 1:length(names)
fprintf(format,names{n},values(n));
end
What about this:
disp(['Friction factor = ' num2str(xxx)])
disp(['Load factor = ' num2str(yyy)])
disp(['Thermal factor = ' num2str(zzz)])