Message Boards Message Boards

0
|
182 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Problem with running script using import

If I create a file through a program and save the data in a folder on the desktop I can import the data to be used in another program but if I turn off mathematica and reopen the program that imports the data I can no longer import it and if I can import the data, the script doesn't run perfectly, which doesn't happen when I run the program when I generate the folder data without turning off mathematica

6 Replies
caminhoDesktop = "C:\\Users\\Felipe\\Desktop\\lalpa2";
arquivos = {
    "lalpa_gh.txt",
    "lalpa_zeros.txt",
    "lalpa_final.txt",
    "lalpa_zerosverdadeiros.txt",
    "lalpa_ii2.txt",
    "lalpa_ii3.txt",
    "lalpa_ii4.txt"
};

gh = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[1]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[1]]]], Print["Arquivo não encontrado: ", arquivos[[1]]]]
zeros = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[2]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[2]]]], Print["Arquivo não encontrado: ", arquivos[[2]]]]
final = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[3]]], Import[caminhoDesktop <> "\\" <> arquivos[[3]]], Print["Arquivo não encontrado: ", arquivos[[3]]]]
zerosverdadeiros = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[4]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[4]]]], Print["Arquivo não encontrado: ", arquivos[[4]]]];
ii2 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[5]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[5]]]], Print["Arquivo não encontrado: ", arquivos[[5]]]];
ii3 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[6]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[6]]]], Print["Arquivo não encontrado: ", arquivos[[6]]]];
ii4 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[7]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[7]]]], Print["Arquivo não encontrado: ", arquivos[[7]]]]

jet4 = Import["zeros.txt"];
jet = ToExpression[jet4];
jotit = Import["final.txt"];
minus = Import["zerosverdadeiros.txt"];
minus1 = ToExpression[minus];
let2 = jet;
gt = let2 - minus1;
let22 = let2 - gt;
let2 = ToExpression[let22];
jotitvv3 = StringJoin["1", StringJoin[Table["0", {let2}]], jotit];
vvv = ToString[jotitvv3];
ee3 = ToExpression[vvv];
ii31 = Import["ii3.txt"];
ii3 = ToExpression[ii3];
ii41 = Import["ii4.txt"];
ii4 = ToExpression[ii4];
ii21 = Import["ii2.txt"];
ii2 = ToExpression[ii2];
hh = Import["gh.txt"];
hh2 = ToExpression[hh];
ee3 = dd;
question = {x} /. Solve[(ii2*ii3*x + ii4)/(ii2*ii3*x) == dd, x];
N[%];
send = ii2*ii3*question + ii4;
send2 = Flatten[send];
send3 = Flatten[send2];
answer = DecimalForm[send3];
a = {x1} /. Solve[(ii2*ii3*x1 + ii4)/(ii2*ii3*x1) == dd, x1];
dd = ee3;
letters = (ii2*ii3*a)*dd;
letters1 = ToString[letters];
digits = IntegerDigits[letters, 256];
digits2 = Flatten[digits];
gh = hh2;
hj = Take[% , -1];
bb = Partition[digits2, 4];
bg = Partition[bb, hj];
image = Image[bg, "Byte",ColorSpace->"RGB" ,ImageSize -> gh]
img = image
labImg = ColorConvert[img, "LAB"];
i get an image correctly if after generating the numbers ii2,ii3,ii4 and others is kept under mathematica turned on ...if turn it off and turn it on again the image is no longer reconstituted...

Arquivo não encontrado: luis_gh.txt

Arquivo não encontrado: luis_zeros.txt

Arquivo não encontrado: luis_final.txt

Arquivo não encontrado: luis_zerosverdadeiros.txt

Arquivo não encontrado: luis_ii2.txt

Arquivo não encontrado: luis_ii3.txt this is the answer i get

caminhoDesktop = "C:\\Users\\Felipe\\Desktop\\luis2\\luis";
arquivos = {
    "luis_gh.txt",
    "luis_zeros.txt",
    "luis_final.txt",
    "luis_zerosverdadeiros.txt",
    "luis_ii2.txt",
    "luis_ii3.txt",
    "luis_ii4.txt"
};

gh = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[1]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[1]]]], Print["Arquivo não encontrado: ", arquivos[[1]]]];
zeros = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[2]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[2]]]], Print["Arquivo não encontrado: ", arquivos[[2]]]];
final = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[3]]], Import[caminhoDesktop <> "\\" <> arquivos[[3]]], Print["Arquivo não encontrado: ", arquivos[[3]]]];
zerosverdadeiros = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[4]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[4]]]], Print["Arquivo não encontrado: ", arquivos[[4]]]];
ii2 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[5]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[5]]]], Print["Arquivo não encontrado: ", arquivos[[5]]]];
ii3 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[6]]], ToExpression[Import[caminhoDesktop <> "\\" <> arquivos[[6]]]], Print["Arquivo não encontrado: ", arquivos[[6]]]];
ii4 = If[FileExistsQ[caminhoDesktop <> "\\" <> arquivos[[7]]],  

ToExpression[Import[caminhoDesktop <> "\" <> arquivos[[7]]]], Print["Arquivo não encontrado: ", arquivos[[7]]]]; the files exist and have different numbers in it and the name is correct...

Not sure what the issue is, but here some advice:

  • Use the FileNameJoin function to build file paths instead of string concatenations.
  • Run your code a command at a time to see where it breaks.
  • If FileExistsQ tells you that a file doesn't exist, try using the FileNames command on the containing directory.
  • For question legibility use launch/quit instead of on/off.
POSTED BY: Gustavo Delfino

Hi Gustavo...thank you for your interest...you see the folder is still open after i turn off the mathematica...but anyscript that uses the data stored in the folder or the script that uses it does not work properly after i turn it on again,but If i turn on mathematica and keep it opened it works fine

Hello Luis. I find your question hard to follow, specially given the total lack of source code. Anyway, if I understand correctly you are claiming that a file written using Mathematica is deleted when you quit Mathematica. That would be weird. I only know of self-deleting files when using a PersistentObject but not when using Export which I assume you are using.

POSTED BY: Gustavo Delfino
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract