I have some tests, the result of each test must be saved in .mat file.
For example:
funcation test (test)
if test1
results1
Matrix(i_row)=results1
save ('test.mat','Matrix')
elseif test2
results2
Matrix(i_row)=results2
save ('test.mat','Matrix')
elseif test3
results3
Matrix(i_row)=results3
save ('test.mat','Matrix')
end
end
I want to find in test.mat file the three matrix, however when I test my function i just found one matrix,
could you please help me?
Your question isn't worded properly, but if what you're asking is why doesn't it save all three results but it only saves the first one, then it's because you're using elseif.
If you want all 3 tests to run, just use if ... end for each test.
Related
I'm trying to write a function that will return the most recent 'closing' value in a csv file containing the data of a cryptocurrency. The csv file contains 6 columns and about 900 rows and I'm looking to only pull one element of the table.
However, I seem to faced a fair bit of difficulty in pulling this off for some reason. The function below returns values from the column I want, however it seems to be pulling values from the very bottom of the document (whereas I want the most recent values).
Also, just a side note to explain what I was attempting to do with the 'count'. Since I'm expecting the value I want to be located on the second row, I wanted my for loop to only iterate through two lines of the file. However, as the result of the function went on to reveal to me, as it currently stands with the counter I'm returning two values from the function.
I understand there must be a much less convoluted way of getting the information I need so am open to any solution to the problem. Though, that being said, I'd be really interested to see where I went wrong here as I'm fairly new to Python.
Thanks a lot!
def csv_to_close(csv_file):
with open(f"{csv_file}.csv", 'r') as csvfile:
csv_file = csv.reader(csvfile)
running = True
count = 0
while running == True:
if count < 2:
for column in csv_file:
close = column[4]
count += 1
else:
running = False
print(close)
I am totally clueless how to get around to get the following kinda result from the same table in MySQL.
Required Result:
The raw data as shown in below image.
Mc_id and op_id can be different. For example, if mc_id is 4 and op_id is 10 then it has to loop through each vouid and extract done_on_date, again it has to loop through for the same mc_id 4 and op_id 10 and extract done_on_date where done_on_date is after first extracted done_on_date. Here second extracted done_on_date, we refer to, as next_done_on_date, just to distinguish it differently. Accordingly continue till end of the table. I hope I am clear enough now.
The idea is basically to see when was particular operation_id carried out for the said machine having mc_id. First time operation done is refered to as done_on_date and when the same operation carried out for the same machine next time, we refer to as next_done_on_date but actually inside the database table it is done_on_date.
Though let me know if anything yet to be clarified
I have following csv file:
col1, col2, col3
"r1", "r2", "r3"
"r11", "r22", "r33"
"totals","","",
followed by 2 blank lines. The import is failing as there is extra comma at the end of the last data row and most probably will fail because of the extra blank lines at the end.
Can I skip the last row somehow or even better stop import when I get into that row? It always has "totals" string in the "col1".
UPDATE:
As far as I understood from the answers that it is not possible to do that with Flat File. Currently I did that with the "Script Component" as a source
You can do it by reading the row as a single string.
Conditionally split out Null and left(col0)=="total"
in script component you then use split function
finally trim("\"")
I know of nothing built-in to SSIS that lets you ignore the LAST line of a CSV.
One way to handle this is to precede your dataflow with a script task that uses the FileSystemObject to edit the CSV and remove the last line.
You will need to create a custom script where you read all lines but the last within SSIS.
This is old but it came up for me when searching this topic. My solution was to redirect rows on the destination. The last row is redirected instead of failing and the job completes. Of course you will potentially redirect rows you don't want to. It all depends on how much you can trust the data.
I couldn't find anything on the site specifically addressing this issue,so I decided to post a question for some help.
I'm trying to run a "BEFORE UPDATE" trigger on a table in my database. The trigger is set to execute after a cron job query runs to evaluate user data. If the data targets are met ,then BEFORE UPDATE trigger kicks in to manipulate additional columns via two simple math formulas.
sqlQuery (via cron job)
UPDATE table1.records SET date_created=IF(expiration_date<(CURDATE()),IF(postCOUNT>0,CURDATE(),'error'),date_created)
BEFORE UPDATE TRIGGER (created via phpMyAdmin cPanel)
1. BEGIN
2. IF NEW.date_created != OLD.date_created THEN
3. SET NEW.date_created=New.date_created;
4. SET NEW.expiration_date = NEW.date_created + 2;
5. SET NEW.postCOUNT = OLD.postCOUNT-1;
6. END IF;
7. END
Now I'm sure there are far better ways of coding to accomplish this task but everything seems to working until the math formula in LINE 5 of the trigger. Instead of subtracting "1" from OLD.postCOUNT, the formula keeps subtracting "2". I'm baffled as to why this is happening,the formula seems straight-forward. I've even tried other numbers in the formula and still the answers are never correct.
Any advice or insight would be greatly appreciated.
Thanks in advance!
I already asked a Question Here.
My this question is just a step ahead to same problem.
I have a delphi code which works perfectly for calling report.
But, now I wanted to show a MessageBox before opening rpt file.
I tried to query it separately for record count and then decide for MessageBox. But, this solution is having a worst case where a aprticular report's query itself takes 3 mins to execute and then again querying while opening rpt it takes 30 sec to load (in second query it takes less time may be because of some data may present in buffer/temp place,etc.).
qPODPhy.close;
qPODPhy.SQL.clear;
qPODPhy.SQL.text :='select * from ViewName';
qPODPhy.Open;
If qPODPhy.RecordCount < 1 Then
MessageBOx('No data To Display...');
Else
Begin
crRep.Somproperties := Initialization
.
.
.
CrRep.SQLQuery := qPODPhy.SQL.text;
crRep.action := 1
End
My Question is :
How can I show a MessageBox if no record is going to present for particular view's output.
OR
Is there a method where I can open the dataset of .rpt file in delphi code and just check the count of records and make the decision? In short, is there some property of crystalreport component which can do this?
You can do a select count(*) separately, that is much faster.
Or maybe select only one record: SELECT TOP 1 ....
And, as RBA suggested, you can try putting that SELECT COUNT in a stored procedure for even more speed.
Just experiments with these methods to see if/when you've gained enough speed.
Are you pushing the data ? You can probably use ReadRecords method of the ReportDocument and check Rows.Count property. If the report is retrieving the data the you can use the NoData event of ReportDocument.